Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message Box problem / setfocus in access form 1

Status
Not open for further replies.

corbitt

MIS
Feb 22, 2002
73
0
0
US
When I display, "Is Credit Card Number Correct?", in a message box, the user can click no and the code sets the focust to accountnumber field (textbox). I've specified this in the code, but it always sets the focus to the next field.

This is the code behind accountnumber field:

If MsgBox("Is Credit Card Number Correct?", vbDefaultButton1 + vbYesNo) = vbNo Then
accountnumber.SetFocus

My ultimate goal is get the user to insert a new credit card number. Is there a workaround this problem? Is there alternate way to get them back to the field. Or should I display an input box where they can input the correct number?

Thank you in advance.

Jeremy
 
The code looks good but check a couple of properties...

1) that the control is specified as a tab stop
2) that the control is enabled and/or not locked
Good Luck,
Mike T
 
Thanks for the post..

I checked those values. They are okay.

Any other suggestions?

Jeremy
 
try me.accountnumber.SetFocus

or forms!frmTheForm!txtAccountnumber.setfocus


BobSchleicher

 
Thanks for the help, but that wasn't successful either.

If you happen to think of something else, please post it.

Thanks,

Jeremy
 
Jeremy,

Change your code:
If MsgBox("Is Credit Card Number Correct?", vbDefaultButton1 + vbYesNo) = vbNo Then
accountnumber.SetFocus

To:

dim x
x = msgbox("Is Credit Card Number Correct",vbYesNo)
If x = vbYes then
accountnumber.setfocus
Endif


 
Global search your code for string "focus" - I suspect there's one somewhere, with a pesky side effect.

No jive! [afro] ROFL!! -------
"What is your favourite colour?" "Blue! No! Yell"
 
Actually, Gates. I believe Corbett may have left out the Endif on the original code.

mac


 
Perhaps, re the endif - but my answer was a serious one, reflecting back to one day when I insanely had a setfocus in a timer event. Can't recall what I was smoking at the time. [pipe]

-------
"What is your favourite colour?" "Blue! No! Yell"
 
Gates & Mac,

I'm not missing an endif and I couldn't find a focus in my code. Here's part of my code:

Dim NumberReenter1 As String

NumberReenter1 = InputBox("Please Reenter The Account Number.", "Input")

If NumberReenter1 <> accountnumber Then
accountnumber = &quot;&quot;
accountnumber.SetFocus
Else
End If

Also, it is enabled, it is not locked, and it is a top stop.
Do you think it will not set focus because I'm setting the focus back to the same field as the code is written behind?

Jeremy
 
It may be, Jeremy. Place the test and set focus code in Got_Focus event of the next field to get focus. I've had to result to this tactic. Let us know if it works.

mac
 
Jeremy. See my explanation in your other post, &quot;Data comparison TextBox vs InputBox. I believe it is what you need. I understood your request a little better in that post.

mac
 
Textbox events fire in a speicific order. You may need to change where you display the msgbox. Which event are you using - Before_Update, After_Update, On_Exit?

If you display the message in After_Update, the On_Exit event will fire after the user clicks a button. The cursor will then move to the next object on the form even though you set focus in the After_Update event.

A better way to handle this kind of validation is to place the message box in the On_Exit event of the textbox. If the validation fails and you want to stay in the same textbox, just set Cancel=True. And focus will remain in the textbox. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains &quot;Suggestions for Getting Quick and Appropriate Answers&quot; to your questions in the SQL Server forum. Many of the ideas apply to all forums.
 
Have you got something else on the form called accountnumber?
I would suggest changing the text box noane to txtaccountnumber and trying again.
 
It works! Thanks for the help. Since the event was AfterUpdate, the setfocus defaulted to the next field. The fix (cheesey..but it worked):

SetFocus to next field
SetFocus to accountnumber field

I guess it's a workaround to the AfterUpdate problem.

Thanks for your time everyone.

Jeremy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top