vba code

  • Thread starter Thread starter Taher
  • Start date Start date
T

Taher

Hi there

I have a form which has two option buttons. And there is a
combo box. I want to write a code which if
the option value is 1(user selects first option button)
and the combo box is null it gives a msgbox.
But when option is 2(user selects 2nd option button 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.
 
I do not see anywhere that you have set the value of "varEnteredValue" which
you are testing. I would have expected you to refer to the Option Button or
the Option Group which contains the Option Buttons, rather than to an
uninitialized variable.

Examples would be something like:

If Me!optFirst = True Then....

or

If Me!grpOpts = 1 Then ....

Larry Linson
Microsoft Access MVP
 
Back
Top