Results 1 to 11 of 11
  1. #1
    vkumar is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    30

    Question Need help with error message


    I have a data entry form and when I enter a value for a foreign key in the form I want the error to show immediately (you can't add or change a record because a related record is required in table X -(Foreign key value must exist in table X as Primary key value)) not when saving the record after entering all the fields. Thank you for your help.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,630
    You would have to use VBA code and build your own message. One way is in the BeforeUpdate event of the control, check for the value in table X.

    A combobox will restrict users to existing data and then can use the NotInList event to handle new value.
    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
    vkumar is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    30
    Thank you for your reply. I am not familiar with VB code. How do I compare the fields in VB. When a enter a job number in the forms (data entety form), the Job table should have the Job number exist already, otherwise error message should display. The code is comparing the job number entered in the form to the Job number in the job table.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,630
    The easiest method might be a combobox. Then the NotInList event could handle an entry not in the table. Many examples for the NotInList event. Google it. Here is one http://www.blueclaw-db.com/access_no...ed_example.htm
    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
    vkumar is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    30
    Again thank you for your reply. I can't use a combo box. Job table has job numbers and it can change(dynamic), in the invoice form when the user enters invoice, user must enter the job number and it should be already in the job table, if not error message should come up. I am getting the error message at the end when I save the form (FK -PK referential integrity), but I want the error message as soon as the user enters the job number. There are more fields and it is a waste of time for the user to enter the rest of the fields and then getting the message.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,630
    I still don't understand why could not use combobox.

    Alternative is the BeforeUpdate event of textbox with code that searches table for entered value. A DLookup function could do that, something like:

    If IsNull(DLookup("JobNumber", "Jobs", "JobNumber='" & Me.textboxname & "'")) Then
    MsgBox "Job Number not in table."
    Cancel = True
    End If

    Review
    http://office.microsoft.com/en-us/ac...010341717.aspx
    http://www.blueclaw-db.com/access_ev...foreupdate.htm
    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.

  7. #7
    vkumar is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    30
    Hi,
    I tried and it gave me a syntax error. Here is what I have:
    (My table name is Job and the textbox name that I enter the value is named as Job Number, in the Job table the field it is comparing is Job Number.)
    Private Sub Job_Number_BeforeUpdate(Cancel As Integer)
    If IsNull(DLookup("Job Number", "Jobs", "Job Number='" & Me.Job Number & "'")) Then
    MsgBox "Job Number not in table."
    Cancel = True
    End If
    End Sub
    Thank you for your help.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,630
    Whenever spaces or special characters or punctuation (underscore is exception) are in names or a reserved word, must enclose in []. That's why it is a good idea to avoid those name structures.

    If IsNull(DLookup("[Job Number]", "Jobs", "[Job Number]='" & Me.[Job Number] & "'"))

    If JobNumber is number datatype then remove the apostrophe delimiters. Date datatype uses # delimiter.
    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.

  9. #9
    vkumar is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    30
    Thank you, I should have known.
    But I got another runtime error, it says "data type mismatch in criteria expression" when I enter the job number.

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,630
    Did you read the last line of my previous post?
    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.

  11. #11
    vkumar is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    30
    It works. Sorry I didn't read your last line. As soon as I saw the square brackets I got excited and hurried to change it. You saved me today. THANK YOU again for all your help and patience.

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

Similar Threads

  1. Getting A Error Message Please Help
    By cec in forum Access
    Replies: 2
    Last Post: 05-15-2012, 02:31 PM
  2. Getting #Error Message
    By cec in forum Programming
    Replies: 6
    Last Post: 04-18-2012, 02:24 PM
  3. On Error Message
    By rlsublime in forum Programming
    Replies: 5
    Last Post: 03-14-2012, 02:53 PM
  4. error message
    By ngeng4 in forum Forms
    Replies: 85
    Last Post: 03-25-2010, 06:47 AM
  5. If / Then Error Message
    By Schwagr in forum Forms
    Replies: 4
    Last Post: 03-30-2006, 06:28 AM

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