Results 1 to 3 of 3
  1. #1
    libraccess's Avatar
    libraccess is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Location
    Napier New Zealand
    Posts
    129

    Search Box Incorrect Entry

    I have a search box on a form that opens another form (frmTraining) at the selected record (almost)

    First Part - as the frmTraining loads with this code to go to a new record

    Private Sub Form_Load()
    If Not Me.NewRecord Then
    RunCommand acCmdRecordsGoToNew
    End If
    Me.TrainDate.SetFocus
    Me.LoggedOn = cboUser
    End Sub

    the code from the search box has a line to return to the previous record (the only record as they are filtered)

    Private Sub btnTrainReport_Click()
    'Message for No Search Entry
    If IsNull(Me.SearchBoxTrainID) Or Me.SearchBoxTrainID = "" Then
    MsgBox "You must enter or select a valid Incident Number", vbOKOnly, "Required Data"
    Me.SearchBoxTrainID.SetFocus
    Exit Sub
    End If

    Dim strWhere As String


    If Not IsNull(Me.SearchBoxTrainID) Then
    strWhere = "IDTraining = " & Me.SearchBoxTrainID

    Exit Sub
    End If
    DoCmd.OpenForm "frmTraining", acNormal, , strWhere


    'as frm opens to new record return to previous
    RunCommand acCmdRecordsGoToPrevious

    End Sub

    So all that works but my question is that if a user enters a ID No. that does not exist
    (why this would happen I don't know as SearchBoxTrainID is an unbound combo)
    a runtime error occurs 2046 this command is not available RunCommand acCmdRecordsGoToPrevious
    of course the form has opened at a blank record

    So my question is should I be trying to handle that error or is there another solution to this
    Thanks

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Could set the combobox LimitToList property to Yes.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    libraccess's Avatar
    libraccess is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Location
    Napier New Zealand
    Posts
    129
    how could i overlook that - simple might not be good - it might be best
    thanks once again

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

Similar Threads

  1. Replies: 1
    Last Post: 06-18-2013, 08:33 PM
  2. Search Field on entry form
    By Rhubie in forum Forms
    Replies: 7
    Last Post: 03-14-2013, 07:04 PM
  3. Replies: 1
    Last Post: 06-27-2012, 12:35 PM
  4. Replies: 2
    Last Post: 06-08-2012, 11:22 AM
  5. Replies: 1
    Last Post: 12-30-2008, 08:58 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