Results 1 to 6 of 6
  1. #1
    Me.Howard is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2015
    Posts
    16

    Error checking

    In a form I am adding a new record to TblRequirement


    The form data entry property is set to yes
    In a text box I enter a job number
    In a second text box I do a LookUp from a different table to populate
    This works well as long as the job number is valid
    I am checking for valid job number with the following code.

    Private Sub Job_Click()
    If IsNull(Job) Or Job < 1000 Or Job > 9999 Then
    MsgBox "Invalid Job Number - Reenter"
    DoCmd.Close
    DoCmd.OpenForm "FrmRequirementAdd"
    End If
    End Sub

    This does not catch the null or the < or the >
    What am I doing wrong

    Thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    Could use a multi-column combobox to offer valid job numbers and set LimitToList property to yes. http://datapigtechnologies.com/flash...combobox3.html

    Then instead of DLookup, expression in textbox can reference column of combobox.

    No VBA needed. But, if you want to add a job number not in the combobox list, use VBA in the combobox NotInList event. https://www.accessforums.net/access/...ate-55139.html

    Is Job a text or number type field?
    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
    Me.Howard is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2015
    Posts
    16
    Job is a number field.
    Why cant I check the validity as shown in the code in the original post?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    I am not sure. Looks like it should.

    If you want to provide db for analysis, follow instructions at bottom of my post.

    Did you consider the combobox suggestion?
    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.

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Why would you put this code in the OnClick event of the Textbox you're validating? With Data EntryProperty set to Yes you can only enter New Records, and the Job field will always be Null when you click into the Textbox!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    Doh! Good catch, Linq!
    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.

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

Similar Threads

  1. Error Checking in a text box
    By Paul H in forum Forms
    Replies: 2
    Last Post: 07-23-2015, 01:02 PM
  2. Error Checking Boxes
    By CementCarver in forum Access
    Replies: 2
    Last Post: 06-12-2013, 04:27 PM
  3. Error Checking within Form
    By phd4212 in forum Forms
    Replies: 1
    Last Post: 05-09-2012, 02:46 PM
  4. Error 0 problem with error checking
    By SemiAuto40 in forum Programming
    Replies: 4
    Last Post: 12-07-2011, 12:21 PM
  5. Date error checking
    By oediaz in forum Programming
    Replies: 2
    Last Post: 03-26-2010, 12:08 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