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

Tabbing our of Required field 1

Status
Not open for further replies.

CMooreJr

Technical User
Feb 20, 2003
217
US
Hey all! I need to do something which I'm sure is very simple if you are a programmer! I have a field called project_nbr on several forms and is in the first TAB order. I want to make it manditory to input a project_nbr (simple enough) BUT I want it to prompt them not if they try to save the record, but if they tab or click out of the box and it is empty. I'd like a dialog box to appear asking them to put one in. I imagine I would put it on the "LOST FOCUS" procedure, but I'm not sure how to write the code. Can you guys please help!

Thanks!
 
Hi
Assume your ProjectNumber text box is called txtPjNumber

As you said, you can put code in the Lost Focus event of the text box as follows:

--Beginning Code

If Me.txtPjNumber = 0 Or If IsNull(Me.txtPjNumber) Then
msgbox "Please enter Project Number"
Me.othercontrol.SetFocus
Me.txtPjNumber.SetFocus
End If
----
OR
----
If Nz(Me.txtPjNumber,0) = 0 Then
msgbox "Please enter Project Number"
Me.othercontrol.SetFocus
Me.txtPjNumber.SetFocus
End If

--End of Code

The Me.othercontrol.SetFocus is because Access sometimes refuses to set focus on the current control.

Nz(Expression,Value) assignes the Value to the Expression if the Expression is Null.

Please look up Nz in Help for a better explanation.

Hope that helps.

OwenTech
 
On Lost Focus....

Dim StrField as Single
Strfield = YourTxtBox.Value
if StrField < 1 then 'assuming it's a #
MsgBox &quot;Please input the project number&quot;
Exit Sub
end if


This should do it. You could have an input box to ask them, but I think it is simpler just not to let the user go anywhere until it is filled.

Note:
Single is for numbers, you may use
Integer for whole number only
String for text

The criteria is if the value does not exceed 1.
you may also substitute (if StrField < 1 then)
with &quot;if isnull(StrField) then&quot; to reflect that there are no digits in the box
hope this helps.
&quot;The greatest risk, is not taking one.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top