Program flow in Access/VBA

Discussion in 'Programming' started by ecawilkinson, Sep 1, 2006.

  1. #1
    Hi,

    I am new to Access and VBA although I have good experience in Java and C. I have been "thorwn in at the deep end" where I work due to a staff resignation and have been told to get on with the programming tasks in the Access database.

    I am having difficulty with certain matters of program flow. I have a form in datasheet mode which is used to edit a table (lets call it "tempTable"). When the user has finished editing, he shuts the form (by pressing "X" in the top right corner). So far so easy. This table "TempTable" is now used to drive a query which updates another table. Again, no problem here. Now I need to delete the table "TempTable". However, at this point, I get error 3211 - table is still locked to another user/object. I assume this is because the code to run the query and delete the table is in the On Close code section. Unfortunately, I do not know where else to put it. The query can only be run when the user has finished editing the table that is why I put the code in On Close section of the form. How can I get the code to delete the table to run AFTER the form has been closed? I need it to be done "in the background" without the user needing to know anything.
    I have tried calling a new form from the on close() and putting the file deletion code somewhere in the new form. It now works as the table is no longer locked to the datasheet form. However, I do not want the user to have to do anything or even see anew form. I'm sure this can be done and is blindingly obvious to an experienced Access programmer. It is very frustrating for me not know how to perform a simple task that I could easily accomplish in c or Java.

    I realise I may be going about things in totally the wrong way as I have no training/experience in Access/VBA coding at all until this baptist of fire. If so, any suggestions on how to proceed would be much appreciated.

    Thank you,
    Chris
     
    ecawilkinson, Sep 1, 2006 IP
  2. ecawilkinson

    ecawilkinson Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I have found a way of doing what I want but it seems a bit awkward to possibly be the correct way. See if you agree.

    From the on close section of the form I open a new form (mode: hidden). Set a timer event to 1 millisecond which closes this new form. In the on close section of this form, I delete the table. This works fine but I cannot believe it is the recommended way.
     
    ecawilkinson, Sep 1, 2006 IP