runtime error

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
 
G

George Nicholson

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
 
K

Khartoum

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top