How to open a ODBC-connection in vb6.0
Posted on 2005-03-26
Have a project in vb6.0 that use this connection to the db.
Public Sub start_access()
Dim Msg As String
Dim application As String
Dim dbs As String
Dim workgroup As String
Dim user As String
Dim password As String
Dim cTries As Integer
Dim xy As Boolean
Dim var2 As Integer
Dim clsImport As New Access.AllModules
Dim int2 As Variant
Dim fso As New FileSystemObject
accstartet = False
' This is the default location of Access
application = "J:\Program Files\Microsoft Office\Office\MSACCESS.EXE"
' Use the path and name of a secured MDB on your system
dbs = App.Path & "\Lyse111.mdb"
' This is the default workgroup
workgroup = App.Path & "\PB2000.mdw "
user = "JHDEv"
' Use a valid username
password = "caesar.vicit" ' and correct password
' x = Shell(application & " " & Chr(34) & dbs & Chr(34) & " /nostartup /user " & user & " /pwd " & password & " /wrkgrp " & Chr(34) & workgroup & Chr(34), vbHide)
x = Shell(application & " " & Chr(34) & dbs & Chr(34) & " /nostartup /user " & user & " /pwd " & password & " /wrkgrp " & Chr(34) & workgroup & Chr(34), vbMaximizedFocus)
On Error GoTo WAITFORACCESS
Set accObj = GetObject(, "Access.Application") ' Turn off error handling
On Error GoTo 0 ' You can now use the accObj reference to automate Access
accstartet = True
Set accObj = Nothing
WAITFORACCESS: ' <--- This line must be left-aligned. ' Access isn't registered in the Running Object Table yet, so call
' SetFocus to take focus from Access, wait half a second, and try ' again. If you try five times and fail, then something has probably
' gone wrong, so warn the user and exit. SetFocus
If cTries < 5 Then
cTries = cTries + 1
Sleep 500 ' wait 1/2 seconds Resume
MsgBox "Access is taking too long. Process ended.", vbMsgBoxSetForeground
Screen.MousePointer = vbDefault
Have different forms in my project that uses a adodbc-object control. This control
is set up with a odbc-connection.
What i want is to use a odbc connection insted of the code, that start access.
Is there a way to do this ?
Onother thing is that i must use accObj.Run...
I use a library in the access database, to start different functions.