Results 1 to 6 of 6
  1. #1
    aolough is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    5

    How to force data entry on form without receiving the following popup boxes

    Hi, I want to force data entry on one of my combo/text boxes on a form. The following code works however it's messy because after it displays the message "Please Choose Item", the user is presented with two popup boxes to navigate, as shown in the attached images. Is there a way around this? Below is the code:


    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.Combo70) Then
    MsgBox "Please Choose Item"
    Me.Combo70.SetFocus
    Cancel = True
    End If
    End Sub
    .

    Thanks in advance

    Click image for larger version. 

Name:	Untitled.png 
Views:	16 
Size:	21.0 KB 
ID:	8808Click image for larger version. 

Name:	Untitled2.png 
Views:	8 
Size:	26.3 KB 
ID:	8809

  2. #2
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    I doubt very much whether your problem is caused by the procedure you have published; I can see nothing wrong. Something else is triggering an attempt to save the record and (I can't enlarge the first picture) it looks like a JET DB error coming to the fore, maybe a missing mandatory value or a referential integrity problem.

  3. #3
    aolough is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    5
    Hi Rob,

    Thanks for the reply. This is the error message.

    "You can't save this record at this time. Microsoft Access may have encountered an error while trying to save a record. If
    you close this object now the data changes you made will be lost . Do you want to close the database object anyway?"


    Sorry I'm only at this a week or so - I'd be very grateful if you could suggest how I could identify and locate the problem?

    Regards,
    Áine

  4. #4
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Don't apologise, we've all been there, we all started somewhere.

    Typically this error occurs for any number of reasons when you close the form. As I said previously, your before update procedure is fine but it contains a Cancel = True assignation. Now when Access tries to close a bound form it checks to see if the form is 'dirty,' specifically if there is something to be stored or updated in the database, and if there is the before update event will fire. If nothing has changed and Combo70 is still null then you are telling Access not to store the changes. Access does not know what to do and asks via this error message.

    OK, that I think is what is happening but does not answer why it's happening. Something later in the process is trying to close the form. What you need to do is issue a Me.Undo statement before the close (so there are no outstanding changes) but without seeing more of your project I can't help specifically.

  5. #5
    aolough is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    5
    Hi Rob,

    I'm clicking the save & close button, so that's when the beforeupdate fires, right? That displays the correct message and then I presume the cancel=true tells access not the save the record. I don't get the Me.Undo part though? I tried adding it in the next line but I'm still getting the same error. I don't want access to do anything until the user addresses the issue and populates the empty field and reclicks save & close.

    I'm attaching my file. I appreciate your time so far

    Áine

    Inventory Management5.zip

  6. #6
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    I'm clicking the save & close button, so that's when the beforeupdate fires, right?
    Right!

    I often include a 'Cancel' button for overcoming such situations. My code typically looks as follows, it may work for you.

    Code:
    Private Sub btnCancel_Click
    Me.Undo
    DoCmd.Close acForm, Me.Name
    End Sub
    Beware I wrote the foregoing off the top of my head.

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

Similar Threads

  1. Replies: 5
    Last Post: 08-12-2013, 12:53 AM
  2. Replies: 3
    Last Post: 07-20-2012, 11:55 PM
  3. data entry form
    By gbmarlysis in forum Forms
    Replies: 1
    Last Post: 02-01-2012, 12:14 AM
  4. Material Receiving Form
    By Solanthus in forum Forms
    Replies: 1
    Last Post: 01-26-2012, 08:25 AM
  5. Replies: 1
    Last Post: 12-02-2010, 03:04 PM

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