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

VB: How to have one event code refer to another

Status
Not open for further replies.

CharlieT302

Instructor
Mar 17, 2005
406
US
Can you have a VB code that calls another?
 
do you have some code that you are working on that doesn't work properly? Could you post the code? What are you trying to do?

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual
 
On my form, when I move to a new record, the "RecNum" field is populated with the data from the previous record. The problem is that it only works if the "Recnum" field receives the focus.

I want the focus to move to the RecNum field to trigger its "On Focus" event when the user clicks the date field. I have a "On focus" event for the date field to do this. However, I receive the message that the focus cannot be moved to the "RecNum" field. I was hoping there was another way of triggering the RecNum event.


Private Sub RecNum_GotFocus()

SendKeys "^'", True
ServPro.SetFocus
If IsNull(ServPro) Then SendKeys "^'", True
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.GoToControl "doe"
End Sub

Private Sub DOE_GotFocus()
If IsNull([RecNum]) Or IsNull([ServPro]) Then
RecNum.SetFocus
End If

End Sub
 
Rather than have your code in the GotFocus event, move it to a separate sub in the form. You can then call this sub from anywhere in the form that you need to (including the GotFocus event.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top