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

Customer Number

Status
Not open for further replies.

dominicgingras

Technical User
Jul 15, 2002
53
CA
I want that every time a user create a new workorder that the focus remain on a specific control (Account Number) until the user enter that account number. I tried to use the setfocus on before update and then create a validation rules on the control but without success. Any clue?
 
Private Sub txtAddr1_Exit(Cancel As Integer)
If Nz(Me!txtAddr1, "") = "" Then
Cancel = True
End If
End Sub

This is pretty crude. You'd want to include a message box to tell the user why this is happening. You'd also want to check for this in the Unload event of the form, so that you can cancel that event if the user tries to close the form w/o putting in that data.

I haven't really thought about the implications of this; you're going to want to think about it a bunch. And you should always give the user some way to bail out of the record creation if he or she doesn't have the info.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
If I read this the right way that will make a user not getting out off the form until he enter a customer number.

My point is that I need to make sure that he enter a customer number before making anything else when he create a new order.

 
Try checking to see if the field is "" on Lostfocus and then Cancel the procedure and the SetFocus back to the text box in question after displaying your nasty messagebox telling them to enter some data.

I would do the code for you but I'm not a great Access programmer and thus would probably give you the wrong syntax. I think my logic is pretty solid though.
 
Try:

'Declare a txtValidate variable
Dim txtValidate as Boolean

Private Sub txtAcctNo_LostFocus()

'set validation variable to true
txtValidate = True

'Test for required entry
If IsNull(txtAcctNo) Or txtAcctNo = "" Then
MsgBox "Enter value befor continuing."

'set failure of validation
txtValidate = False
Exit Sub
End If

End Sub

'Test validation on the next text box to get the focus.
'If validation failes, you will be able to pass the focus
'back to the AcctNo text box.

Private Sub nextTxtBox_GotFocus()

'check AcctNo validation
If txtValidate = False Then AcctNo.SetFocus

End Sub

ERM
 
I'm sorry, the last Sub should read:

Private Sub nextTxtBox_GotFocus()

'check AcctNo validation
If txtValidate = False Then txtAcctNo.SetFocus

End Sub
ERM
 
The logic is almost solid. The problem is that there is no cancel parameter for the LostFocus event, which is why I used the Exit event.

Dominic, you could also make it so that when a new record is added, the focus is set to that control--that way the user will have to set the customer number first.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top