Results 1 to 12 of 12
  1. #1
    Secue is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2013
    Posts
    33

    Question SearchForRecord command - How to validate if record is not found

    Hi:



    I'm using the command SearchForRecord on a form to populate it based on the ID number I look using the comand. I have and afterupdate event on a combo box with the following code:

    DoCmd.SearchForRecord , , acFirst, "[ID] = " & Str(Nz(Screen.ActiveControl, 0))

    It is working fine any time I select an ID from the list all files on the form are properly populated with the data for that specific record. As I have te option to enter manually the valor on the ID combobox (I do this since when I have a lot of values I do no want to go trought the complete list, just want to enter the number I'm interested) if I enter a number in the list, there is not issues, the form is populated, but if I enter a number ID that is not in the list, nothing happens, I mean the information from previous record found continues populated.

    I want to get a verification when the number I enter is not on the list, to trigger a message indicating that the number is not on the list and warn to the user.

    I hope my request is clear.

    Thank you.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Have you looked at the "NotInList" event of the ComboBox?

  3. #3
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    Check out the NotInList Event.

    Dale

  4. #4
    Secue is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2013
    Posts
    33
    I tried form the propoerties of the combo box, but nothing happen. On the on update property of the combo box, I'm running a macro with the followwing information:
    Action: SearchForRecord
    Arguments: , , First, ="[ID] = " & Str(Nz(Screen.ActiveControl,0))

    As this is executed on after update, not sure if mavro for On Not in List will be executed. I added a code just to beep on this event, but it does not do anything.

    I may need to use code instead and embedded Macro, but any way I will need to know how to verify for the number entered on the combo box.

    Thank you.

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    It looks like you went on holiday. Remove any macros or code from the ComboBox and the NotInList event will fire for you.

  6. #6
    Secue is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2013
    Posts
    33
    RuralGuy:

    Thank oyu for your recomendation, I have a code asigned to the even after update for this comobox, whic is to display the information for the selected record ID number, which is the main funtion. So I can not eliminate it.

    Thank you.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Do you have LimitToList set to YES?

  8. #8
    Secue is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2013
    Posts
    33
    RuralGuy:

    No I have it set to NO. I set it on that way thinking that other way I will not be able to enter manually the number of the ID.
    Now I set it to YES and every time I enter a number that isnot part of the list I got the error mesage. What is waht I wanted.

    Now, maybe I'm trying to abusse, but is there any way I can set something to cathc the error and instead of show the mesaahe box from the sytem I can set the text in the message box? as the mesaage in in english, and my database will be used for users speaking english but even espeaking speanish, I'm setting all the messages on both lenguages.

    Thank you.

    If this isnot posible, at least I have now a restirction message when I enter a number not on the list.

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Not sure I understand your request about the Message Box. Do you *not* want to catch it in the NotInList event?

  10. #10
    Secue is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2013
    Posts
    33
    What I mean is that now that I set LimitToList to YES, if I enter a number that is not in the list I got a message from the Access indicating that number entered is not on the list. What I want is to cehck for this same condition, but I want to custom the message that is displayed. Is this posible?

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Use the NotInList event http://msdn.microsoft.com/en-us/libr...ffice.11).aspx
    The code should work even if there are other events with code.

    Or

    BeforeUpdate event to search the table for value, use DLookup() function.

    NotInList is probably the better approach, it's what it was designed for.
    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.

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Be sure and set the Response value in your code to keep the system message from displaying.

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

Similar Threads

  1. Replies: 13
    Last Post: 12-17-2012, 07:52 PM
  2. Replies: 4
    Last Post: 07-31-2012, 04:33 PM
  3. Need help on transferring found record
    By awsmitty in forum Access
    Replies: 1
    Last Post: 01-22-2010, 09:11 PM
  4. Replies: 2
    Last Post: 11-04-2009, 09:45 PM
  5. if record not found through combo box
    By wasim_sono in forum Forms
    Replies: 2
    Last Post: 08-04-2008, 06:32 AM

Tags for this Thread

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