Click to See Complete Forum and Search --> : Help needed


zigona
April 1st, 2001, 04:54 PM
Hi guys!

Can, please anyone tell me, how do set Database to Dataenvironment in code rather then by properties?

The problem is, that I have a Datareport with Data environment and the connection to the Database is made in its properties. When I'll deploy my App I don't know if it will be in the same folder as it is on my PC.

I was thinking something about like: Dataenvironment1.databasename=App.Path & "\MyDataBase"

If it's possible, please DO help me.

God bless you all! Ales

Rouven Thimm
April 7th, 2001, 12:47 PM
Hi!

If I understand you correctly, you want to be able to dynamically access this database. You can do so exactly as you proposed. In case you are using a data-control:
Formname.Controlname.Databasename = Filename


In case you are using a Databaseobject:
set DB = OpenDatabase(Filename)


Only be careful with one thing. I have noticed, I think, this may not be reliable :-), that App.Path does not always end on \ but sometimes does (Depending on installation in Subdir or directly on a drive). So what I always do is create a variable named AppPath and do the following:
Dim AppPath as string
AppPath = App.Path
If Right(AppPath, 1) <> "\" then AppPath = AppPath & "\"



So you will only have to specify your filename as:
Filename = AppPath & "MyDatabasefile.mdb"


or whatever your database is named like...

Hope this helps you

Raptors Fan
April 7th, 2001, 11:10 PM
Try this, it works for me... In DataEnvironment1 enter:


private Sub DataEnvironment_Initialize()
Connection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\database_name.mdb;" & _
"Mode=ReadWrite|Share Deny None;" & _
"Persist Security Info=false"
End Sub