Results 1 to 14 of 14

Thread: Record verification

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    6

    Record verification

    Hi all,

    I have never programmed in VB and I created a database that has a search field. The problem is when a user types in a data that is not in the database, it would still look give a result. For example, the form has a field to search for a lot number. If the user puts a lot number that is not in the database, how would I code it in VB? I appreciate the help I can get. Thanks.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Record verification

    Welcome to the forums.

    Moved from the FAQ section

    I made a guess in terms of where to put this. I need to know the version of Visual Basic that you are using. Is it VB6 or VB.NET?

    Also, what database are you using?

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    6

    Re: Record verification

    I created a MS Access database and using VB6. Thanks for the help.

  4. #4

  5. #5
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,514

    Re: Record verification

    You could use a select query.
    Code:
    Dim rs as New ADO.Recordset
    
    rs.Open "select field1,field2  from sometable where field1=<somevalue>",yourconnection
    if rs.Recordcount then
        msgbox "found item"
    else
        msgbox "Not found"
    end if

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    6

    Re: Record verification

    This is the code for the find button:
    vb Code:
    1. Private Sub FindCmd_Enter()
    2.      Dim rs As Object
    3.      
    4.     Set rs = Me.Recordset.Clone
    5.     rs.FindFirst "[UDLLotNumber] = '" & Me![Text142] & "'"
    6.     If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    7.  
    8. End Sub
    UDLLotNumber is a field in the form and Text142 is the field where users can type in UDLLotNumber to search. My concern is that how would I code a situation wherein the user typed in a UDLLotNumber that is not in the database? I created the database using MS Access. Thanks for the help.
    Last edited by jayceecatbagan; Nov 13th, 2007 at 10:36 PM.

  7. #7
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,514

    Re: Record verification

    Not sure I understand, but this is how you handle both situations

    If <item is found> then
    ' do something when found
    else
    ' do something when not found
    endif

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    6

    Smile Re: Record verification

    The algorithm would be something like the one below:

    If user enters a UDLLotNumber that is not in the database in the search field

    Then

    Display a message "UDL Lot No. is not found or not in the database."

    Else

    Find the record


    How would I code this on the OnClick method of the Find command button I created in the MS Access form?

    Thanks again for all the help.

  9. #9
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Record verification

    Quote Originally Posted by jayceecatbagan
    ...How would I code this on the OnClick method of the Find command button I created in the MS Access form?

    Thanks again for all the help.
    Based on your last post you make it clear that you are not using VB6 but rather VBA (VB 6.3) and so I've moved your thread to this forum.

  10. #10
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,514

    Re: Record verification

    I described that in my first post.

  11. #11

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    6

    Re: Record verification

    But how would I code it in VB? I don't have any experience coding in VB. Thanks for the help.

  12. #12
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,514

    Re: Record verification

    Look in the "FAQ" section of the Visual basic 6 and Earilier and Database Development forums. You'll find alot of help there on General VB6 programming and ADO programming.

  13. #13

  14. #14

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    6

    Re: Record verification

    I would say in both places. I created the command button in the access form and on the OnEnter event procedure, I inserted the code that I mentioned on the previous thread. I tested the Find button with the above mentioned code and it works. My concern is that when a user enters in the search field (control source is a column in the table I created, UDLLotNumber) a UDLLotNumber that is not in the table, it should give a message that the UDLLotNumber the user is searching for is not in the database. How can I accomplish this with a VB code, which is tied to the Find button?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width