Append query doesn't work

J

John B

Hi,
I run the following append query from a button in a form.
Unfortunatly this query doesn't populate the Table on the first click.
I need to run the query twice. Is there any reason?

Private Sub InsertOrderDetails_Click()
On Error GoTo Err_Update_Click
If IsNull(Me.txtCalOutput) Then
MsgBox ("Insert Date"), vbInformation, "Attention"
Me.txtCalOutput.SetFocus
End If

Dim OrderDetail As String ' First query
stDettaglioOrdini = "Qry_Order Details_Update"
DoCmd.OpenQuery OrderDetail, acNormal, acEdit

Dim stData As String ' Second query
stData = "Data_Temp"
DoCmd.OpenQuery stData, acNormal, acEdit

MsgBox ("Insert Completed."), vbOKOnly,
"Table Oder Details"

Exit_Update_Click:
Exit Sub

Err_Update_Click:
MsgBox Err.Description
Resume Exit_Update_Click
End Sub
 
J

Jeff Boyce

John

Do you get any error messages?

How are you determining that no records have been appended (i.e., are you
checking the table)?

Have you inserted a breakpoint in the code and "stepped-through",
line-by-line, making sure if and how each line of code functions?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
J

John B

Hi Jeff,

Thanks for your help.
Do you get any error messages? NO.

How are you determining that no records have been appended (i.e., are you
checking the table)?
Yes, I am checking the table contents. Then, If I click again on the button
all the records appear into the table.
Have you inserted a breakpoint in the code and "stepped-through",
line-by-line, making sure if and how each line of code functions?
No and I don't know how to do.

Thanks again for Your help.
Regards
John B
 
R

Rastro

I will need to see the querys but first this will not work because the
variable you need has another name:

'You create the "OrderDetail" variable
Dim OrderDetail As String ' First query

'Here you initialize the "stDettaglioOrdini" variable
stDettaglioOrdini = "Qry_Order Details_Update"

'Here you use the "OrderDetail" variable (=null string)
DoCmd.OpenQuery OrderDetail, acNormal, acEdit

Also this isn't right:

If IsNull(Me.txtCalOutput) Then
MsgBox ("Insert Date"), vbInformation, "Attention"
Me.txtCalOutput.SetFocus
End If

If you require a valid date in txtCalOutput to continue you need to exit sub
when you check that is missing.

If Not isDate(txtCalOutput) then
MsgBox "Insert Date", vbInformation, "Attention"
txtCalOutput.SetFocus
Exit Sub
End If

Try this.

Rastro



John B said:
Hi,
I run the following append query from a button in a form. Unfortunatly
this query doesn't populate the Table on the first click.
I need to run the query twice. Is there any reason?

Private Sub InsertOrderDetails_Click()
On Error GoTo Err_Update_Click
If IsNull(Me.txtCalOutput) Then
 
J

Jeff Boyce

John

Check HELP re: Breakpoint.

Open the form in design view.

Right-click on the command button and select Properties.

Scroll down the list until you get to the OnClick event -- on the far right
of that line there's an ellipsis (...) - click it to open the VBA Editor.

Check HELP re: Breakpoint.

Add a Breakpoint before the first line of code in the OnClick procedure.

Use the File | Close... to return to the form. Save it with the changes,
open the form, click the button.

Your procedure should open up highlighting a row of code -- use the
single-step toolbar button to step line by line.

Check HELP re: Breakpoint.

There's a lot more, but this should get you started...

Good luck!

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
J

John B

Thanks for Your help.
With your suggestions, now the append query, runs OK.

Regards
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top