Results 1 to 6 of 6
  1. #1
    Monterey_Manzer is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    164

    More Reliable/Efficient: Setting form control value or using query to update table?

    Hi All,



    I'm curious which method is the better way to set/update values in a table. I have a form in which users are filling out data including start and end dates. In most cases the end date can be calculated from other pieces of data present (i.e. start date and time duration). In most cases I simply use a button and some VBA code to set the value of the control in the form. However, in some cases the time duration value is null and in those cases I prompt the user to enter this value and then use a couple UPDATE queries to set both the time duration and end date values directly to the table. I finish this up with a Refresh of the form to display the calculated end date. I was just wondering if there is one method that is demonstrably better than the other.

    Thanks!
    Ryan

  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,926
    Are you using InputBox to get the user input?

    Don't understand why you use UPDATE query. If the record and field are already available on form, just set the field value with the user input as you do with the code behind button.

    Could just nag the user with a message box, set focus on the control, and have them input there.
    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
    Monterey_Manzer is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    164
    I do use an InputBox to get User Input. The value the user is entering is kept on a separate table and for the vast majority of records it already exists. That is why I don't have a control on the form for that field. Honestly I really have to restrict what data users can manipulate in order to keep the data accurate.

    I then use an update query to update the time duration data in the table where what is stored. In my code I go on to use the variable I assign to the InputBox value in the VBA code that sets the end date. However, I had thought of putting in a second update query that sets the calculated end date value in the table directly rather than going through the form and I was wondering what the merits of each approach would be.

  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,926
    Using UPDATE to edit record in table that is also open on a form where an edit may have already been initiated could cause issue. This might be like two users trying to edit same record at same time. Seems I ran into that before and had to modify processes.
    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
    Monterey_Manzer is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    164
    Perhaps I should have the time duration as a locked field on the form and when my code triggers the request for input, rather than having an InputBox pop up I could set focus and highlight the duration field. I could then trigger the calculation of the end date in the After Update event for the duration field. Do you think that would be more stable?

    I would unlock the duration control to allow the user to enter the data and then lock in again during the After Update event.

  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,926
    Yes, I do that same sort of process, except BeforeUpdate might be better event for calculating and populating the end date.
    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: 10
    Last Post: 02-20-2013, 07:04 AM
  2. Replies: 1
    Last Post: 06-19-2012, 06:12 PM
  3. Replies: 1
    Last Post: 05-18-2011, 07:23 AM
  4. Replies: 6
    Last Post: 03-14-2011, 09:37 AM
  5. Most reliable way to edit form data in VBA...?
    By samalter in forum Programming
    Replies: 0
    Last Post: 06-23-2006, 12:39 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