Help with the code.......

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

Can someone help me get this code right below: I have 3 comboboxes on a
form, what I need is when all the combo boxes have had a value selected to
them to apply the Select Case statement below to create the variable strDate.

Thanks

Private Sub cboContractStatus_AfterUpdate()
Dim StrDate As Long

If IsNull(cboContractStatus) And IsNull(cboNumberSelect) And
IsNull(cboTimeperiod) Then
End If
Exit Sub

Else
Select Case cboTimeperiod.ListIndex
Case 0
StrDate = cboNumberSelect * 1
Case 1
StrDate = cboNumberSelect * 7
Case 2
StrDate = cboNumberSelect * 30
MsgBox (StrDate)
End If

End Sub
 
You don't say what your specific problem is, but it would seem to me that
you need to change the condition in the If statement to

If IsNull(cboContractStatus) Or IsNull(cboNumberSelect) Or
IsNull(cboTimeperiod) Then

You want to exit if any of the comboboxes is null, not only if all of them
are null. As written, you'll be trying to use the Select Case statement as
soon as one of the comboboxes has been selected.
 
Hi

Sorry I should have been more clearer. I only want to generate the string
strDate when all comboboxes have been selected.

The error message I am getting is 'Else without If' on the else line.

Thanks again
 
Okay: the problem is the EndIf you have in the first half of the If
statement. All you need is the Exit Sub.

However, note that my previous advice still holds.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top