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

List box problem?

Status
Not open for further replies.

janetlyn

Technical User
Jan 29, 2003
516
US
I have a form with a CheckMark, Number field, and Text field. If the Check is true, there should not be any values in the Number or Text fields. If the Checkmark is False, there has to a number and text. The text is what is giving me problems. I have my Row Source Type as "Value List", and my Row Source, to be

""; "Hours"; "Trips"

My code is:


Private Sub NEXT_Click()
'If ([CKNoObs] = No) Then
' MsgBox "CkNoObs is No."
'End If
'If ([HorT] <> "Hours") Then
' MsgBox "H or T equals something besides hours"
'End If
'If ([HorT] <> "Trips") Then
' MsgBox "H or T equals something besides Trips"
'End If
If (([CKNoObs] = No) And ([HorT] <> "Hours")) Then
MsgBox "Please select Hours or Trips before proceeding.", vbOKOnly
[HorT].SetFocus
If (([CKNoObs] = No) And ([HorT] <> "Trips")) Then
MsgBox "Please select Hours or Trips before proceeding.", vbOKOnly
[HorT].SetFocus
Else
MsgBox "Should go to next form"
DoCmd.GoToRecord acDataForm, "FRM-EOM-ObHrsTrps", acNext
End If
End If
End Sub

The 'Code is where I was trying to find out where it was not working. It answered correctly if Checkbox was false. When I put "Hours" in, it gave me both the hours and trips message. So, it does not recognize Hours and Hours. Sorry my terminology is so bad.

Can you tell from my code what is not correct? Thanks, JL
 
The proper way to see waht valus is in th echeck box is
x=me!check1.value

If the boxe is checked X = be -1 or True
not checked wil be 0 or False
I am assuminh [CKNoObs] is the name of your check box

So try this:

If Me![CKNoObs].value = False then
MsgBox "CkNoObs is No."
end if



DougP, MCP, A+
 
Although I changed my code to reflect your properly written code, that part is working; it is the HorT part of the code that is not working. This is the code:

If (([CKNoObs] = No) And ([HorT] <> "Hours")) Then
MsgBox "Please select Hours or Trips before proceeding.", vbOKOnly
[HorT].SetFocus
If (([CKNoObs] = No) And ([HorT] <> "Trips")) Then
MsgBox "Please select Hours or Trips before proceeding.", vbOKOnly
[HorT].SetFocus
Else
MsgBox "Should go to next form"
DoCmd.GoToRecord acDataForm, "FRM-EOM-ObHrsTrps", acNext
End If
End If

When I fill in the proper fields, then select the "Next" record control, it does not work. This code is in the OnClick of the NEXT control. Any other ideas? JL
 
After a quick look, it seems like you might need the following:

[HorT].SetFocus
Exit Sub

HTH,
Debbie
 
OK, I thought about it some more and here's what should work:

Code:
If Me.CkNoObs = 0 Then
  If [b]IsNull(Me.HorT)[/b] Then
    MsgBox "Please select Hours or Trips before proceeding."
    Me.HorT.SetFocus
  ElseIf Me.HorT <> "Hours" [b]And[/b] Me.HorT <> "Trips" Then
    MsgBox "Please select Hours or Trips before proceeding."
    Me.HorT.SetFocus
  ElseIf [b]IsNull(Me.NumberField)[/b] Then
    MsgBox "You must enter a number."
    Me.NumberField.SetFocus
  End If
Else
  DoCmd.GoToRecord , , acNext
End If

Debbie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top