Results 1 to 13 of 13
  1. #1
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162

    Hold updating underlying table while filling Access form & update table at the click of a button

    My Access database has 3 tables Materials, Orders and Shipments. Materials table is a list of all importable


    material and this table is used as a lookup table for the Orders table which puts the name of material
    according to the required order. Orders table is related to Shipments table by one to many relation.
    I want to make a form by which I could scroll through all the records of Shipments and Orders table as
    well as to add new records. But my requirement at this point is that, I want the form not to update the
    table while I input data in each field, but to HOLD THE UPDATING UNTIL I HAVE FINISHED ALL OF THE
    FIELDS AND UPDATE AT THE CLICK OF A BUTTON ON THE FORM. Side by side Shipments table has autonumbered
    Primary Key which has to generate automatically in the form.
    I am still a novice in the VBA arena, and I don't have any idea of ADO and DAO. Please help me out.

  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,928
    Data is committed to table when:

    1. close table or form

    2. move to another record

    3. run code

    Code can prevent the record update. Otherwise, use unbound controls and code to save data. Example of one method for date/time, text, number type fields:

    CurrentDb.Execute "INSERT INTO tablename(field1, field2, field3) VALUES(#" & Now() & "#, '" & Me.textboxname & "', " & Me!ID & ")"
    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
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Dear June7,
    I think in the last line you have provided SQL syntax to transfer data from an Unbound form to table. But i'm not sure about the "&" in the 3 type of fields. However it might be better for me to use a BOUND form as then i could chek the previous data in the table as well. IF YOU COULD PROVIDE ME VBA CODE TO PREVENT RECORD UPDATE I could have make use of that.

  4. #4
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Do you want to not save the data until ALL fields are filled in or only some fields?
    Example:
    If IsNull([CustomerID]) Then 'Require a Customer.
    MsgBox "A Customer is Required" 'Optional.
    [CustomerID].SetFocus
    End If
    HTH

  5. #5
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Hi Burrina,
    I'd like to hold the savings untill ALL fields in the form/sub-form are filled.

  6. #6
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Here is an Example:
    Dim Ctrl As Control
    For Each Ctrl In Me.Controls
    If Ctrl.ControlType = acTextBox Or Ctrl.ControlType = acComboBox Then
    If IsNull(Ctrl) = True Then
    MsgBox "Hey...You didn't fill in all the data " & _
    "fields for this record. Please do so now.", _
    vbExclamation, "** Required Data Missing **"
    Cancel = True
    Exit For
    End If
    End If
    Next Ctrl

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Could set fields as required in table settings. Then Access can nag the user if fields not completed, they will be returned to the record to complete. Won't save until the required fields are completed.
    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.

  8. #8
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    Burrina,
    I guess "Cancel=True" is the line that prevents the form from saving, isn't it? AND WILL THIS AUTOMATICALLY SAVE THE FORM ONCE ALL OF THE FIELDS ARE FILLED IN?
    However there is one textbox in my form which may remain empty depending on a checkbox field. In that case what should I do?

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Options:

    1. Use the control Tag property. Have some indicator such as "Required" in the property then the code can be:

    If IsNull(Ctrl) = True And Ctrl.Tag = "Required" Then

    2. just check for the name of that control:

    If IsNull(Ctrl) = True And Ctrl.Name <> "the name" Then
    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.

  10. #10
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    In what event of the form should i put the procedure? I tried it in the Form_current event, but in the line "Cancel=True" it highlights the Cancel in blue and says "Varialbe not defined".

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    In the form BeforeUpdate procedure.
    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.

  12. #12
    bubai is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Dhaka
    Posts
    162
    This time no error, but it is not doing what it is supposed to do. If i partially complete the form and close it, it doesn't refrain me and happily adds the record to the underlying table. What i need is a procedure that i can add to a Button click procedure and that then will add records to the table, not before that.

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    How are you closing the form - custom button or X close? I always disable the X close and use custom button but that does complicate the process because the button event fires before the BeforeUpdate event.

    Consider this example which does not use BeforeUpdate but returns user to the form to complete entry.
    Code:
    Private Sub Close_Click()
    If Not IsNull(Me.Rate) Then
        'save record and close form
        DoCmd.RunCommand acCmdSaveRecord
        DoCmd.Close
    End If
    End Sub
    If you want an option to completely abort the record entry/edit, that will mean some more code. At this point, user can press ESC to undo record edits.

    Is a form/subform arrangement involved?
    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: 1
    Last Post: 02-19-2014, 11:02 AM
  2. Replies: 5
    Last Post: 02-12-2014, 11:52 PM
  3. Replies: 6
    Last Post: 05-10-2012, 08:20 PM
  4. Form not updating underlying table
    By Kirsti in forum Forms
    Replies: 8
    Last Post: 02-10-2012, 12:23 AM
  5. Replies: 7
    Last Post: 01-08-2012, 06:20 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