• Loop statement

    Author
    Topic
    #352155

    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

    Viewing 0 reply threads
    Author
    Replies
    • #511386

      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.

      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
    Viewing 0 reply threads
    Reply To: Loop statement

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: