Results 1 to 10 of 10
  1. #1
    seriestoo2 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    5

    Question Ask for employee ID,check against a table of registered IDs,give error if not in tabl


    Hey guys, I'm new to visual basic and I'm trying to create a piece of code that would, after clicking a particular button, prompt the user for an employee ID (preferably using InputBox), then check the ID against an existing table of registered IDs. It would return an error and prompt the user to try again if null or an unregistered string is given.

    I appreciate any help.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    What do you have so far? Tools include InputBox, DCount() and an If/Then/Else block. More on the DCount() syntax:

    DLookup Usage Samples
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    seriestoo2 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    5
    This is it:

    Pin = Trim(InputBox("Enter Employee PIN", "PIN Required"))

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    If DCount(...) = 0 Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    seriestoo2 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    5
    Ok here's my updated code. It keeps returning "Runtime error: 2471"

    Code:
    Line1:        
            entry = Trim(InputBox("Enter Employee PIN", "PIN Required"))
            If entry = "" Then Exit Sub
            empl = DLookup("[Employee]", "EmplPIN", "[PIN]=entry")
            If empl = Null Then
                    MsgBox "PIN not found"
                    GoTo Line1
                Else
                    MsgBox ("Employee registered as" & empl)
                End If

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    It would help to know the data types of the fields, but try changing these 2 lines:

    empl = DLookup("[Employee]", "EmplPIN", "[PIN]=" & entry)
    If IsNull(empl) Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    seriestoo2 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    5
    OK I really appreciate all your help so far. Now I'm getting runtime error 6, overflow.
    The PIN field is a number, Employee is text.

    Code:
            Dim entry As IntegerLine1:
            entry = InputBox("Enter Employee PIN", "PIN Required")
            empl = DLookup("[Employee]", "EmplPIN", "[PIN]=" & entry)
            If IsNull(empl) Then
                    MsgBox "PIN not found"
                    GoTo Line1
                Else
                    MsgBox ("Employee registered as" & empl)
                End If

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    If the first line isn't a typo you've jammed it all together instead of having separate lines. Given the use I'd add

    Dim empl As Variant

    If it still errors, what value is being entered? Integer can only handle up to roughly 32k. You want Long if the value is bigger than that.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    seriestoo2 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    5
    Thank you so much! The issue was that some PINs were 5 digits, putting them above 32k.

    Final question: is there a way I can have a msgbox if a user enters too many digits, or text, instead of a runtime error appearing?

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    You can test for text by testing entry with IsNumeric(). You can test for digits either by testing for > 99999 or using the Len() function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 1
    Last Post: 04-14-2014, 11:44 AM
  2. Replies: 12
    Last Post: 11-23-2012, 11:41 PM
  3. Replies: 1
    Last Post: 05-15-2012, 06:47 AM
  4. error "OLE Server isn't registered"
    By newtoAccess in forum Forms
    Replies: 1
    Last Post: 12-26-2010, 10:51 AM
  5. HyperLink error "No Program registered ..."
    By RycherX in forum Access
    Replies: 1
    Last Post: 02-09-2010, 03:36 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