Making combo boxes compulsory

  • Thread starter Thread starter arsxr49
  • Start date Start date
A

arsxr49

At the moment I have a form with 4 synchronized combo boxes and a button
at the bottom. When the button is pressed the options chosen in the
combo boxes are sent to a table. The problem I have at the moment is
that I need it so that the users have to select an option in all 4
combo boxes before they can submit the results to the table. Any
ideas?

Also does anybody know how to make it so that if a certain option is
chosen in the first combo box the other 3 are automatically filled in?

Regards,

Ste
 
In the OnClick event of the command button you could run a little validation
procedure before opening the report/query(whatever it is the button is
supposed to do)

eg.

Dim lvalid as long 'form module level variable

In the Onclick event of command button
lvalid = validateentry()
if lvalid = false then
exit sub
else
openreport code or whatever
end if


Function validateentry()
validateentry = false ' this sets the default

if nz(combo1.value,"") = "" then
msgbox "Please select from drop down list"
combo1.setfocus
exit function
end if

if nz(combo2.value,"") = "" then
msgbox "Please select from drop down list"
combo2.setfocus
exit function
end if

validateentry = true ' if the code gets to here then everything must be ok

end function

HTH

Al
 
arsxr49 said:
At the moment I have a form with 4 synchronized combo boxes and a button
at the bottom. When the button is pressed the options chosen in the
combo boxes are sent to a table. The problem I have at the moment is
that I need it so that the users have to select an option in all 4
combo boxes before they can submit the results to the table. Any
ideas?

Also does anybody know how to make it so that if a certain option is
chosen in the first combo box the other 3 are automatically filled in?


I sometimes use event procedures like the ones below for the
"chained" combo boxes. I'm not familiar with the details of
your form so I'm not sure where you would disable the
command button for new or existing records.

Private Sub Combo0_BeforeUpdate(Cancel As Integer)
With Me.Combo0
.Dropdown
Cancel = .ListIndex < 0
End With
End Sub

Private Sub Combo0_AfterUpdate()
Me.cmdSubmit.Enabled = False
With Me.Combo2
If Len(Trim(Nz(Me.Combo0, ""))) > 0 Then
.Requery
.SetFocus
If .ListCount = 1 Then
.Value = .ItemData(0)
Combo2_AfterUpdate
Else
.Value = Null
.Dropdown
End If
End If
End With
End Sub

Private Sub Combo2_BeforeUpdate(Cancel As Integer)
With Me.Combo2
.Dropdown
Cancel = .ListIndex < 0
End With
End Sub

Private Sub Combo2_AfterUpdate()
Me.cmdSubmit.Enabled = False
With Me.Combo4
If Len(Trim(Nz(Me.Combo2, ""))) > 0 Then
.Requery
.SetFocus
If .ListCount = 1 Then
.Value = .ItemData(0)
Combo4_AfterUpdate
Else
.Value = Null
.Dropdown
End If
End If
End With
End Sub

Private Sub Combo4_BeforeUpdate(Cancel As Integer)
With Me.Combo4
.Dropdown
Cancel = .ListIndex < 0
End With
End Sub

Private Sub Combo4_AfterUpdate()
With Me.cmdSubmit
If Len(Trim(Nz(Me.Combo4, ""))) > 0 Then
.Enabled = True
.SetFocus
Else
.Enabled = False
End If
End With
End Sub
 
Back
Top