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

Making form fields required with an SQL back-end

Status
Not open for further replies.

vlitim

Programmer
Sep 2, 2000
393
GB
I have a form where I want to force the user to enter certain fields

The supporting database is SQL so I cannot update the table properties (linked to sql server) to required

i have tried using validation rules i.e. is not null but these are ignored

is there a way to do this?



 
within the 'ON click' properties of the close form button, setup criteria that checks these fields have an entry.

We'll assume you need criteria in text boxes - 'fieldA' & 'fieldB'

Put in Event Procedure code as-

If (IsNull(fieldA) Then
Beep
MsgBox "Please enter required criteria"
DoCmd.GoToControl "fieldA"
Exit Function
End If

If (IsNull(fieldB) Then
Beep
MsgBox "Please enter required criteria"
DoCmd.GoToControl "fieldB"
Exit Function
End If

The above code will check if fields A & B are blank, if so they'll flag up the message and set the curser flashing in that particular field.

Hope this helps.
 
sorry, slight typing error, code should be:-

If IsNull(fieldA) Then
Beep
MsgBox "Please enter required criteria"
DoCmd.GoToControl "fieldA"
Exit Function
End If

If IsNull(fieldB) Then
Beep
MsgBox "Please enter required criteria"
DoCmd.GoToControl "fieldB"
Exit Function
End If

p.s. If your field names have spaces in them (i.e. field A) either change name to fieldA or field_A or put it into the code as [field A]

cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top