Results 1 to 3 of 3

Thread: Loop statement

  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Loop statement

    Either I'm tired or dumb.. Not sure which.. But I would like to have the If MsgBox part of this code to loop.. It works fine if you enter the wrong receipt# the first time but then nothing.. Any help is appreciated.. Thanks..
    Private Sub HiddenTextbox_KeyPress(Cancel As Integer)
    Me.RecordSource = BuildDataEntry()
    If Me.RecordsetClone.RecordCount = 0 Then
    Cancel = True
    If MsgBox("Receipt# Not Found, Click Ok To Enter A New Receipt# Or Cancel To Stop.", vbExclamation + vbOKCancel, "IDC Receipt System Message:") = vbOK Then
    Me.RecordSource = BuildDataEntry()
    End If
    Else
    DoCmd.CancelEvent
    End If
    Exit Sub
    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Loop statement

    Try this. Since I can't guess what BuildDataEntry() does, I can only fix your code. However, I'd suggest that you test the recordset for records before you set the recordsource instead of after. I know that recordsetclone.recordcount is handy, but setting the recordsource property requeries the form ... over and over and over.

    <pre>Private Sub HiddenTextbox_KeyPress(Cancel As Integer)
    Me.RecordSource = BuildDataEntry()
    If Me.RecordsetClone.RecordCount = 0 Then

    Do
    If MsgBox("Receipt# Not Found, Click Ok To Enter " _
    & "A New Receipt# Or Cancel To Stop.", _
    vbExclamation + vbOKCancel, "IDC Receipt System " _
    & "Message:") = vbOK Then
    Me.RecordSource = BuildDataEntry()
    Else
    Cancel = True
    Exit Do
    End If
    Loop until me.recordsetclone.recordcount >0
    Else
    Cancel = True
    DoCmd.CancelEvent
    End If
    Exit Sub
    End Sub</pre>

    Charlotte

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Loop statement

    Thanks Charlotte[img]/w3timages/icons/alien.gif[/img]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •