G'Day
I have a program that uses a vba routine to open a form in Access 2007. The operator can then enter dates into the form and print required information.
However as soon as the form opens the routine ends and Access immediately shuts down before the operator can enter the dates.
Is it normal for Access to close in this case if the routine ends or am I using an incorrect command.
I've been told that this used to work in Access 2003
Here is the vba code . Thanks for looking.
Sub Report
'Starts Access and opens "PrintForm" for inputting required data record day and printout Form
Dim DBPath As String
On Error Resume Next
DBPath = "C:\Documents and Settings\Administrator\My Documents\Database.mdb"
'Attempt to get any currently running Access object
Set MyAccessObject = GetObject(, "Access.Application")
If Err.Number = 429 Then 'If = 429, Access is not running
Set MyAccessObject = GetObject(DBPath) 'Get Access object
MyAccessObject.DoCmd.OpenForm "PrintForm", acNormal 'Opens the information input form
ElseIf Err.Number = 0 Then
MsgBox "Access is already running." & vbCrLf & vbCrLf & "Shutdown and restart to try again"
Else
MsgBox Err.Number & vbCrLf & Err.Description
End If
End Sub
I have a program that uses a vba routine to open a form in Access 2007. The operator can then enter dates into the form and print required information.
However as soon as the form opens the routine ends and Access immediately shuts down before the operator can enter the dates.
Is it normal for Access to close in this case if the routine ends or am I using an incorrect command.
I've been told that this used to work in Access 2003
Here is the vba code . Thanks for looking.
Sub Report
'Starts Access and opens "PrintForm" for inputting required data record day and printout Form
Dim DBPath As String
On Error Resume Next
DBPath = "C:\Documents and Settings\Administrator\My Documents\Database.mdb"
'Attempt to get any currently running Access object
Set MyAccessObject = GetObject(, "Access.Application")
If Err.Number = 429 Then 'If = 429, Access is not running
Set MyAccessObject = GetObject(DBPath) 'Get Access object
MyAccessObject.DoCmd.OpenForm "PrintForm", acNormal 'Opens the information input form
ElseIf Err.Number = 0 Then
MsgBox "Access is already running." & vbCrLf & vbCrLf & "Shutdown and restart to try again"
Else
MsgBox Err.Number & vbCrLf & Err.Description
End If
End Sub