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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error code and set focus 1

Status
Not open for further replies.

VBALearner

Programmer
Jun 28, 2002
10
US
I wrote this vba code in the after update of a text box.

If Me.Dirty Then
If IsNull(Me!Store_No) Then
MsgBox "Store Number Is Invalid, enter valid store number", vbCritical, ""
Me!Store.SetFocus
Exit Sub
End If
End If
Store_No is from another table. It is an invisible box if store does not match store number.

MY question is I can't seem to get the focus back on store if there is an error. hOw do I do that.

thanks,
Eva
 
If the box is invisible, then it can't have the focus. Is there a reason you would want to do that anyway? A setfocus event maybe?

Todd
 
the invisible box is not the one I want to set the focus on. It is the store box that is visible.

 
A tricky thing with setfocus......I have rarely been able to set focus back to the object I just left, so use the following:

If Me.Dirty Then
If IsNull(Me!Store_No) Then
MsgBox "Store Number Is Invalid, enter valid store number", vbCritical, ""
[/i]Me!someothercontrolonform.SetFocus[/i]
Me!Store.SetFocus
Exit Sub
End If
End If


This will cause access to jump focus to the new control, then back to the original....has worked every time for me. Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCP, Network+, A+
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
My mistake. What happens in debug mode if you put a stop next to the setfocus line. Does that get executed at all?
 
you are normally thrown into debug mode....whereupon you usually hit the F8 key to walk through the code one line at a time....I use this a lot to find errors/validate my code....very useful. Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCP, Network+, A+
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Right. I'm asking what happens when you step through it after you put a stop next to it...
 
When you hit the F8 key, as you go one line ata a time, the code is processed......so you can see eachs tep as it happens...if you open the immediate window at the same time, or hover your cursor over a variable name or soemthing, you can see what thevalue is at that point in the code, etc... Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCP, Network+, A+
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Wow mstrmage1768, you and I are just not on the same page. I was asking VBALearner what actually happened in THEIR code when they stepped through it like you have suggested, not what would happen IF they tried that... :) Either way, glad they got it working.
 
Sorry tsonnenl.....I didn't catch that...thought you were asking what happens when you do this....

[morning] Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCP, Network+, A+
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top