Results 1 to 3 of 3
  1. #1
    coach32 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    47

    Code to return 'No Record exists'


    I have a command button on my form that when pressed will search for a number....
    Code:
    Private Sub Command8_Click()
    Dim str As String
    str = InputBox("What is the Business Number?", "Company")
    str = "*" & str & "*"
    Me.DataEntry = False
    DoCmd.FindRecord str, , False, , True
    End Sub
    If the number doesn't exist in the list, the form shows the first number in the list.
    How do I bring up a message that says the 'Number does not exist'. And if I press 'Cancel' on the button when searching , that also shows the first number on the list, which I would prefer it didn't do.
    Thank you for any help you can give.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,640
    InputBox function not best tool for user input - too hard to validate. Why not a combobox or textbox?

    I've never used FindRecord. Alternatives:

    1. Bookmarks and RecordsetClone to go to record

    2. construct filter criteria and set form Filter property, review: http://www.allenbrowne.com/ser-62.html
    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
    nick404's Avatar
    nick404 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2015
    Location
    Wisconsin
    Posts
    352
    I don't know much about FindRecord.. but could you do an If statement...?
    If IsNull(FindRecord) Then MsgBox "No record exists"
    Just a though,=t.

    Definitely take a look at June' s link. Good reference.

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

Similar Threads

  1. VBA code to check if a record already exists
    By fra90 in forum Programming
    Replies: 3
    Last Post: 11-20-2013, 11:20 AM
  2. Report Code is not allowing return to main code
    By rcwiley in forum Programming
    Replies: 2
    Last Post: 06-16-2013, 10:31 AM
  3. Replies: 4
    Last Post: 12-14-2012, 06:33 PM
  4. Replies: 3
    Last Post: 10-19-2012, 04:30 PM
  5. Goto Record when Duplicate Record Exists
    By rlsublime in forum Programming
    Replies: 13
    Last Post: 03-22-2012, 03:46 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