I have a button on my main db, that opens a second db using hte following code:
----------------------
'Dealing with external objects, use inline error trapping
On Error Resume Next
Dim appAccess As Object
Dim db As Database
Dim strAppPathName As String
Dim strAppName As String
Dim strTimesheetPathName As String
'get pathname of currendb
Set db = CurrentDb
strAppPathName = db.Name 'full path
strAppName = Dir(strAppPathName) 'just app name
Debug.Print strAppPathName
Debug.Print strAppName
'build file pathname for timesheet.mdb
strTimesheetPathName = Left(strAppPathName, Len(strAppPathName) - Len(strAppName))
Debug.Print strTimesheetPathName
strTimesheetPathName = strTimesheetPathName & "ProjectTime.accdb /cmd username"
Debug.Print strTimesheetPathName
'Grab the database if open
Set appAccess = GetObject(strTimesheetPathName)
If Err.Number <> 0 Then
'The database was not open so open it
Set appAccess = CreateObject("Access.Application")
Err.Clear
End If
'Make Access visible
If Err.Number <> 0 Then
MsgBox "There was an error"
Set appAccess = Nothing
Else
appAccess.Visible = True
'nb see Declare Function SetFocusAPI Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Long in General Utilites
SetFocusAPI appAccess.Application.hWndAccessApp
End If
---------------
This code works great to open the other db, and handles wheter the other db is already open or not, but I cant seem to pass the variable to the other db using the startup switch /cmd.
I suspect if I used the shell method it would pass the cmd , but I havnt found any way to test if the db is already open with the shell method.
Ho can I pass a variable to the other db when opening it using VBA
Thanks
Grant
----------------------
'Dealing with external objects, use inline error trapping
On Error Resume Next
Dim appAccess As Object
Dim db As Database
Dim strAppPathName As String
Dim strAppName As String
Dim strTimesheetPathName As String
'get pathname of currendb
Set db = CurrentDb
strAppPathName = db.Name 'full path
strAppName = Dir(strAppPathName) 'just app name
Debug.Print strAppPathName
Debug.Print strAppName
'build file pathname for timesheet.mdb
strTimesheetPathName = Left(strAppPathName, Len(strAppPathName) - Len(strAppName))
Debug.Print strTimesheetPathName
strTimesheetPathName = strTimesheetPathName & "ProjectTime.accdb /cmd username"
Debug.Print strTimesheetPathName
'Grab the database if open
Set appAccess = GetObject(strTimesheetPathName)
If Err.Number <> 0 Then
'The database was not open so open it
Set appAccess = CreateObject("Access.Application")
Err.Clear
End If
'Make Access visible
If Err.Number <> 0 Then
MsgBox "There was an error"
Set appAccess = Nothing
Else
appAccess.Visible = True
'nb see Declare Function SetFocusAPI Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Long in General Utilites
SetFocusAPI appAccess.Application.hWndAccessApp
End If
---------------
This code works great to open the other db, and handles wheter the other db is already open or not, but I cant seem to pass the variable to the other db using the startup switch /cmd.
I suspect if I used the shell method it would pass the cmd , but I havnt found any way to test if the db is already open with the shell method.
Ho can I pass a variable to the other db when opening it using VBA
Thanks
Grant