<sorry for thread hijack>
My vb6 application opens the access data base with the vb6 database name property of the Data1 control. How can I change this to open with explicit coding in the vb coding so I can change the path in a single location?
<sorry for thread hijack>
My vb6 application opens the access data base with the vb6 database name property of the Data1 control. How can I change this to open with explicit coding in the vb coding so I can change the path in a single location?
Short answer: centralize the path in one place (a small startup routine or module) and have every part of the app ask that routine for the path or connection string. That keeps only one editable location when the .mdb moves. This builds on 's question and the suggestions from and (use code and consider ADO), but provides a concrete pattern to adopt across a VB6 project.
Example pattern (standard module):
' modDB.bas
Public gMDBPath As String
Public Sub InitDB(Optional ByVal overridePath As String = "")
If Len(overridePath) Then
gMDBPath = overridePath
Else
gMDBPath = App.Path & "\data\MyDatabase.mdb"
End If
End Sub
Public Function GetADOConnectionString() As String
GetADOConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & gMDBPath & ";Persist Security Info=False;"
End Function Call InitDB once at startup, then open ADO connections with GetADOConnectionString(). If keeping legacy Data controls, they should be initialized from gMDBPath (one assignment at startup). For Access 2007+ (.accdb) use the ACE provider instead of Jet; see common connection strings for both providers at . Notes: store the path in a small config (INI, XML or registry) if it must be editable without rebuilding; prefer UNC paths for network files; ensure correct provider/version for the target machine; and handle exclusive/open locks if multiple clients use the same file.
Jump to Post— debasisdas 580You can set the same property through code as well.
Place the code somewhere in Form_Load ().
You can set the same property through code as well.
Place the code somewhere in Form_Load ().
I would opt for the active x option (ado), save the path to a database and call the main connection from there. Do you know how to achieve this?
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.