user1860787
user1860787

Reputation: 41

Access 2007 VBA DoCmd.Close not working

I know this is probably a stupid question, but you know what they say. I have VBA in an Access Database with commands for On Click. Essentially it is a form with a combo box and timestamp for user login. Once the button is clicked a data entry form will load dependent upon which name is selected from the Combo Box. I would like for the Login Form to close once the data entry form has opened. The problem is that no matter where I put the DoCmd.Close the stupid form won't CLOSE!

In case it matters this form is set to open automatically when a user opens the database.

Below is the VBA for the Event Procedure associated with the button.

Option Compare Database

Private Sub TimeInButton_Click()
Dim strLoginForm As String

If Me.AgentCombo = "Amber" Then
  strForm = "frmCustomersAmber"
ElseIf Me.AgentCombo = "Amanda" Then
  strForm = "frmCustomersAmanda"
ElseIf Me.AgentCombo = "Brett" Then
  strForm = "frmCustomersBrett"
ElseIf Me.AgentCombo = "Marcus" Then
  strForm = "frmCustomersMarcus"
ElseIf Me.AgentCombo = "Terrah" Then
  strForm = "frmCustomersTerrah"

End If


'------------------------------------------------------------
' TimeInButton_Click
'
'------------------------------------------------------------

On Error GoTo TimeInButton_Click_Err

    On Error Resume Next
    DoCmd.GoToRecord , "", acNewRec
    If (MacroError <> 0) Then
    Beep
    MsgBox MacroError.Description, vbOKOnly, ""
End If

DoCmd.OpenForm strForm

TimeInButton_Click_Exit:
Exit Sub

TimeInButton_Click_Err:
MsgBox Error$
Resume TimeInButton_Click_Exit

End Sub

Upvotes: 2

Views: 10096

Answers (1)

mwolfe02
mwolfe02

Reputation: 24227

DoCmd.Close takes optional arguments that will make it much more reliable. For example,

DoCmd.Close acForm, "MyFormName"

Upvotes: 6

Related Questions