runtime error

  • Thread starter Thread starter Khartoum
  • Start date Start date
K

Khartoum

I have a password form: depending on the password a particular form will open
by an 'on click' event as below:

Private Sub okbutton_Click()
If Forms![password form].text_password = "atay" Then DoCmd.OpenForm "Angela
Taylor" _
Else: If Forms![password form].text_password = "dgra" Then DoCmd.OpenForm
"Dave Graham" _
Else: MsgBox "You have entered an incorrect password", vbOKCancel
DoCmd.Close acForm, "password form", acSaveNo
End Sub

When i add the same code to an 'on enter' event it gives me a runtime error
2585, opens the form anyway but highlights:

DoCmd.Close acForm, "password form", acSaveNo

Can anybody shed some light on this
Thanks
 
I'm not a fan of long convoluted single-line instructions, so I don't know
for sure it thats the problem, but I'm thinking the MsgBox and DoCmd.Close
won't work together as written.

I would find the following much easier to read, maintain, expand and debug.

Select case Forms![password form].text_password
Case "atay"
DoCmd.OpenForm "Angela Taylor"
Case "dgra
DoCmd.OpenForm "Dave Graham"
Case Else
MsgBox "You have entered an incorrect password", vbOKCancel
DoCmd.Close acForm, "password form", acSaveNo
End Select
 
Thanks to you both. Losing the acsaveno helped but i eventually changed it to
an afterupdate event and that solved it
John

George Nicholson said:
I'm not a fan of long convoluted single-line instructions, so I don't know
for sure it thats the problem, but I'm thinking the MsgBox and DoCmd.Close
won't work together as written.

I would find the following much easier to read, maintain, expand and debug.

Select case Forms![password form].text_password
Case "atay"
DoCmd.OpenForm "Angela Taylor"
Case "dgra
DoCmd.OpenForm "Dave Graham"
Case Else
MsgBox "You have entered an incorrect password", vbOKCancel
DoCmd.Close acForm, "password form", acSaveNo
End Select

--
HTH,
George

Khartoum said:
I have a password form: depending on the password a particular form will
open
by an 'on click' event as below:

Private Sub okbutton_Click()
If Forms![password form].text_password = "atay" Then DoCmd.OpenForm
"Angela
Taylor" _
Else: If Forms![password form].text_password = "dgra" Then DoCmd.OpenForm
"Dave Graham" _
Else: MsgBox "You have entered an incorrect password", vbOKCancel
DoCmd.Close acForm, "password form", acSaveNo
End Sub

When i add the same code to an 'on enter' event it gives me a runtime
error
2585, opens the form anyway but highlights:

DoCmd.Close acForm, "password form", acSaveNo

Can anybody shed some light on this
Thanks
 
Back
Top