Results 1 to 2 of 2
  1. #1
    DCV0204 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    85

    Filter Form

    Here is my code it works unless I click cancel on the input box. It hangs up on the line I have indicated in red. How can I get it to recognize the cancel button? Thanks.
    Private Sub provid_btn_Click()
    Dim MedID As String
    ' Get Value from Medicaid_ID textbox on the Form:
    Me.provid_btn.SetFocus
    Me.srchprovid.SetFocus
    MedID = Me.srchprovid.Text

    If IsNull(DLookup("[Sak_Prov]", "Sak_Prov", "Sak_Prov = '" & srchprovid & "'")) Then
    ' NAME is Null because the Medicaid_ID doesn't exist.
    DoCmd.OpenForm "Sak_ProvForm", , , , acFormAdd
    ' NAME is not Null because the Medicaid_ID does exist.
    Else
    DoCmd.OpenForm "UpdateCurrentFile", , , , acFormAdd
    Dim frm As Form, strMsg As String
    Dim strInput As String, strFilter As String
    ' Open UpdateCurrentFile form in Form view.
    DoCmd.OpenForm "UpdateCurrentFile"
    ' Return Form object variable pointing to UpdateCurrentFile form.
    Set frm = Forms!UpdateCurrentFile
    strMsg = "Provider ID is already on file." & (Chr(13)) & (Chr(13)) & "Enter Medicaid ID and Update all information per instructions & policy. "
    ' Prompt user for input.
    strInput = InputBox(strMsg)
    ' Build criteria string.
    strFilter = BuildCriteria("Medicaid_ID", dbText, strInput)

    ' Set Filter property to apply filter.
    frm.Filter = strFilter
    ' Set FilterOn property; form now shows filtered records.
    frm.FilterOn = True
    Forms!UpdateCurrentFile!ProvID_iC.SetFocus 'Sets focus to Control ProvID_iC

    End If


    End Sub

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    If the user presses Cancel, the Inputbox() returns a zero length string. So you could try:
    Code:
     'Prompt user for input.
    strInput = InputBox(strMsg
    If Len(strInput) = 0 then Exit Sub
    ' Build criteria string.
    strFilter = BuildCriteria("Medicaid_ID", dbText, strInput)
    
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Filter By Form and Apply Filter Buttons
    By JustLearning in forum Forms
    Replies: 13
    Last Post: 02-18-2015, 01:01 PM
  2. Replies: 5
    Last Post: 02-07-2013, 12:21 PM
  3. Replies: 3
    Last Post: 11-27-2012, 07:20 AM
  4. Replies: 1
    Last Post: 08-16-2012, 01:51 PM
  5. Replies: 28
    Last Post: 03-08-2012, 06:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums