Results 1 to 7 of 7
  1. #1
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187

    Writing\Saving to tables immediately after DAO INSERT

    I am using VBA\DAO to write new records to a table in a shared database (front-end/back-end), which obviously has multiple users. This database is for scheduling meeting rooms and we are trying to avoid availability conflicts when more than 1 person tries to select a time slot(s) at the same time.

    The way it works is, when the form loads, it loads all available slots in the listbox. If 2 users open it prior to the other scheduling the desired slot, they can both see and select the same slots. If one person picks the slots, I want the second person to get an error\msgbox if they pick the same slot(s) stating the slots were already selected. I have most of this taken care of already and works if I write one persons selections and then re-visit the table shortly after, but it seems as if the data isn't being physically written to the table immediately, maybe just sitting in memory.

    The table being written to is not bound to a form, it's manipulated only through VBA code. How can I write\save changes to this table immediately after my DAO INSERT INTO query, which is what writes selected time slots to my table so it can be found by my DLookUp call (used to check for already selected slot(s)) within a second or less?

    How slots are written to my table:


    Code:
    CurrentDb.Execute "INSERT INTO Scheduled (UserName,ApptDate,ApptTime,ApptID) VALUES ('" & strUser & "',#" & strDate & "#,#" & arrTimes(lstStart.Column(0, lstStart.ListIndex)) & "#, " & lngApptID & ");"
    Thanks!

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Are you saying that there is some noticeable lag time after the execution of the Insert?
    Have you tried inserting a Select query to read the Schedule immediately after running the Insert. Or pehaps a msgbox with your DCount?

  3. #3
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187
    The issue is it is not updating the data immediately because DLookup comes up with no results when a INSERT has occurred which should make the DLookUp have results.

    I tested this two ways, running two front-ends on my own machine, and running one myself and my boss on another machine. I selected a time slot on one front end and the same slot on another front end. I then click schedule on both, a second or less apart, and I get scheduled twice on the same slots. The one being scheduled second in line should get a msgbox block stating the slot is taken. It looks like the data is not hitting the table instantly so dlookup is not finding it.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    are you issuing a me.refresh command between the insert an the next time you do a dcount?

    though it sounds like you will have to issue a me.refresh BEFORE you perform the insert as well to make sure it's actually checking the most updated set of records.

  5. #5
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187
    No I am not.. I will try. What exactly does me.refresh do? My form is not bound to this table, if that matters.

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    me.refresh forces an update of your data, so in cases like yours where you're using an unbound form across multiple users one of your users should be 'first' and the second addition should be refused or altered.

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    I thought that the second or subsequent attempts to save would get a message that the record was being held/used by another user.
    I was surprised when you said
    and I get scheduled twice on the same slots.
    I hope rpeare's suggestion works.

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

Similar Threads

  1. Replies: 5
    Last Post: 04-25-2013, 02:38 PM
  2. Saving Pivot Tables
    By djclntn in forum Forms
    Replies: 2
    Last Post: 01-04-2013, 09:00 PM
  3. Using forms to immediately edit/update a table
    By TKTheKid in forum Reports
    Replies: 18
    Last Post: 11-19-2012, 11:58 PM
  4. Immediately update table with form?
    By Rosier75 in forum Forms
    Replies: 6
    Last Post: 06-08-2012, 09:11 AM
  5. Need Help with writing Query for TWO TABLES
    By taimysho0 in forum Programming
    Replies: 4
    Last Post: 01-18-2012, 07:26 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