Append Query not working correctly when opening it through VBA

Sniperbooya

Registered User.
Local time
Today, 08:32
Joined
Jan 30, 2015
Messages
16
Hi Guys,

I have got an append query (Query_AppendTable_Bitumen_Gemiddelde)which adds data into a table.

The user selects 2 items from the list. When closing the form the 2 selected items will be added to Table "Bitumen_gemiddelde".

When manually running this query (double click) the query seems to work just fine. However, when adding a click event to a button and program it to the point where it automatically opens the query it only adds 1 of the selected items.

Code:
Private Sub okpopupselectietoetsgem_Click()
On Error GoTo Err_okpopupselectietoetsgem_Click
     DoCmd.Close acForm, "popupselectietoets"
    Dim stDocName As String
    Dim stLinkCriteria As String
    
    DoCmd.OpenQuery "Query_AppendTable_Bitumengemiddelde"
    DoCmd.Close
    DoCmd.OpenForm "Start"
    DoCmd.OpenQuery "Query_Uncheck_selectie_gemiddelde"
 Exit_okpopupselectietoetsgem_Click:
    Exit Sub
 Err_okpopupselectietoetsgem_Click:
    MsgBox Err.Description
    Resume Exit_okpopupselectietoetsgem_Click
    
End Sub

Query_Uncheck_selectie_gemiddelde unchecks the selected items.



I have tried using
'DoEvents' to buy the Query some more time to run properly. Unfortunately that did not help either.

Any ideas why this could happen?

Thanks a lot!
 
You dont close action queries.
you only open them (tho nothing really opens..it just runs it)

Code:
    DoCmd.OpenQuery "Query_AppendTable_Bitumengemiddelde"
   ''' REMOVE DoCmd.Close
 
Well, the cmd.close is for the form that i want to close when the user clicks on OK.

I think i have found what the issue is here.

As mentioned in my Original post, the form contains checkboxes which gives the user the option to tick 2 of them.

Whenever you tick the second box and click on the button to run the appendquery and close the form, it does not really register the second ticked checkbox as being ticked.

So what i had to do is making sure that as soon as the checkboxes are ticked, the database actually registers them. So now i do a requery first, then run the AppendQuery, and then close the form using cmd.close.

Now it works perfectly.

But i am going to have a look at the databases structure to see if theres anything i can improve.

Anyways,

Thanks for taking the time to reply to me post. Really appreciate it.
Enjoy your weekend!.
 

Users who are viewing this thread

Back
Top Bottom