Results 1 to 8 of 8
  1. #1
    thebionicredneck2003 is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    May 2013
    Posts
    22

    Update a database column when mandatory fields are completed

    Hi guys,



    I have a form with lots of combo boxes and text boxes. They are all linked to various MS Access tables and some of the fields are mandatory. I would like do an check to see if all the mandatory fields are not null i.e. are populated with a value and then run an update query for my master table in the database to flag the records as being complete if all the mandatory fields are populated.

    I have only recently started using access and vba and I know that the general idea would be something like

    If (IsEmpty(tab1.cmb_a)) Then do something

    But I am just blank at the moment on how to proceed, especially on how I can do all the checks and then populate the database.

    Any useful pointers, code or links will be appreciated.


    Thank you

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is your Form bound to fields in a RecordSet? (Each Control has a value in the ControlSource.)

  3. #3
    thebionicredneck2003 is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    May 2013
    Posts
    22
    Hi there, yes my form is bound to the fields in the recordset

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Access will save all of the fields that changed during your edit session. You can check to make sure every control has a value in the BeforeUpdate event of the form using VBA code and Cancel the event if you're not satisfied.

  5. #5
    thebionicredneck2003 is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    May 2013
    Posts
    22
    Hi,

    I know access will save the fields. The specific thing I am looking for is an example, a link or some code snippet of how to do this programmatically and fire off an update query when it notices that all the mandatory fields have been completed.

  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,930
    This 'completed flag' in the master table is a value that is calculated dependent on other data. Conventional wisdom is that saving dependent data is poor design. The value can be calculated when needed, as on a report.

    However, if you must, then code could be in the form's BeforeUpdate event, something like:

    If Not IsNull(Me!field1) And Not IsNull(Me!field2) And Not IsNull(Me!field3) And Not IsNull(Me!field4) Then
    CurrentDb.Execute "UPDATE tablename SET fieldname=True WHERE ID = " & Me.ID
    End If
    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
    thebionicredneck2003 is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    May 2013
    Posts
    22
    Thanks June7 and I agree that it is wrong to save dependent data this way, but for the time being, it has to be this way.
    Your code works brilliantly, but I have been getting this message "The record has been changed by another user since you started editing it. If you save this record, you will overwrite the changes the other user has made".
    Any pointers on how to resolve this and still keep the flag set to true?
    Many thanks

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Is the field you want to update actually included in the form's RecordSource? I had presumed from your narrative that the 'master' table was not part of this form. If the field is available to the form, then simply:

    Me!fieldname = True
    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. Replies: 12
    Last Post: 04-20-2012, 06:34 AM
  2. Query for non mandatory fields
    By pratim09 in forum Queries
    Replies: 2
    Last Post: 09-01-2011, 01:33 PM
  3. Replies: 2
    Last Post: 02-03-2011, 12:41 PM
  4. Completed Database - Packaging?
    By AccessFreak in forum Database Design
    Replies: 1
    Last Post: 01-10-2011, 12:06 PM
  5. Replies: 8
    Last Post: 03-29-2010, 10:20 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