if statement

T

Taher

Hi there

I have a form which has option boxes. And there are
several combo boxes. But i want to write a code which if
the option value is 1 and the combo box is null it gives a
msg.
But when option is 2 and the combo box is null it does not
give any message.

Also when option is 1 and combo box is not null it does
not give any message.

I tried to work on the code but its not working. Below is
the code

Private Sub Command149_Click()
On Error GoTo Err_Command149_Click

Dim msg, style, Mycheck, checkcriteria, response,
Mystring, style1, checkcriteria1, Mycheck1
Dim varEnteredvalue As Variant
msg = "Please enter Approver's Name!"
style = vbYesNo + vbExclamation
Msg1 = " Did you enter Approvers name!"
style = vbYesNo + vbExclamation

'checkcriteria = Forms![PROGRAM SIGN OFF]![PROGRAM SIGN
OFF Subform].Form!Frame23
checkcriteria = Forms![PROGRAM SIGN OFF]![PROGRAM SIGN
OFF Subform].Form!S_Name

Mycheck = IsNull(checkcriteria)
If varEnteredvalue = "1" And Mycheck = True Then
MsgBox msg, style
End If

Mycheck = IsNull(checkcriteria)
If varEnteredvalue = "2" And Mycheck = IsNull
(checkcriteria) Then
DoCmd.Close
End If

Mycheck = IsNull(checkcriteria)
If varEnteredvalue = "1" And Mycheck = False Then
DoCmd.Close
End If



Exit_Command149_Click:
Exit Sub

Err_Command149_Click:
MsgBox Err.Description
Resume Exit_Command149_Click

End Sub

I would appreciate if somebody can help resolve this issue.

Thank you.
 
T

Tim Ferguson

if
the option value is 1 and the combo box is null it gives a
msg.
But when option is 2 and the combo box is null it does not
give any message.

Also when option is 1 and combo box is not null it does
not give any message.

if opt.Value = 1
if IsNull(cbo) Then
msgBox "Can't be empty when it's one"

else
' no message

end if

elseif opt.Value = 2
if IsNull(cbo) Then
' no message

else
' no information given for this

End if

else ' opt neither 1 nor 2
msgbox "System error in opt value"

end if


Hope that helps


Tim F
 

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

Similar Threads

vba code 1
if statment 1
if statement 1
if then msgbox 1
Insert Into error 1
Combo Box with NotInList procedure not working 5
Keep form open until loop completes 2
Yes No message box 5

Top