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

Unable to validate combo boxes any help

Status
Not open for further replies.

nicklewis

IS-IT--Management
Feb 7, 2005
21
GB
Does anybody know how to validate combo boxes because i cant seem to get this code to work

Dim response As String
Dim response2 As String
Dim Response3 As String
Dim response4 As String
Dim response5 As String


If (IsNull(DateId)) Or DateId = "" Then
response = MsgBox("Date field is empty, Please Select a date", vbOKOnly, Error)
Exit Sub
ElseIf (IsNull(PlantId)) Then
response2 = MsgBox("Plant Code field is empty, Please Select a Code", vbOKOnly, Error)
Exit Sub
ElseIf (IsNull(ShiftTypeId)) Then
Response3 = MsgBox("Shift Type field is empty, Please Select a Shift Type", vbOKOnly, Error)
Exit Sub
ElseIf TotalShiftLength = 0 Or (IsNull(TotalShiftLength)) Then
response4 = MsgBox("Shift Length field is empty, Please add a Shift Length", vbOKOnly, Error)
Exit Sub
End If

response5 = MsgBox("Save Completed", vbOKOnly, "Confirmation")
DoCmd.GoToRecord , , acNewRec
 
The usual way to enforce validation rules is to code all the checks in the BeforeUpdate event procedure of the form, playing with the Cancael argument.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
would the code still be the same as above because if so wouldnt that on a button be doing thesame thing?
 
How are ya nicklewis . . . . .

[blue]Are you using the right column[/blue] for the comboboxes?

If the [blue]column of interest[/blue] is the 1st column ([blue]column index starts at zero and includes any Column Widths set to zero[/blue]) then you can use the [purple]implied[/purple] form of referencing the control:
Code:
[blue]Me![purple][b]ComboboxName[/b][/purple]
[purple]or[/purple]
Me![purple][b]ComboboxName[/b][/purple].Value[/blue]
If not, you have to specify the column:
Code:
[blue]Me![purple][b]ComboboxName[/b][/purple].Column([purple][b]?[/b][/purple])[/blue]
You can also reference the textbox portion of the combobox, just remember the [blue]combobox has to have the focus first:[/blue]
Code:
[blue]Me![purple][b]ComboboxName[/b][/purple].Text[/blue]
As for validation:
Code:
[blue][purple]For Text use:[/purple]
   If Trim(Me![purple][b]ControlName[/b][/purple] & "") = "" Then
[purple]For numeric use:[/purple]
   If IsNull(Me![purple][b]ControlName[/b][/purple]) Then[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top