Code Running to fast

  • Thread starter Thread starter Padarick
  • Start date Start date
P

Padarick

Greetings,
I have a form with a button that calls a delete macro,
runs a loop to add data to the table, then opens a report to
display/print the data.

It seems to be displaying the report without the data even thought the
data is in the table.
If I run the report outside of this routine it shows the data.

It is as if the code is executing out of order.
I have tried showallrecords and doevents.

This has come up over and over in Access 2003.
I have set timers to kick off the second half of the code after waiting
but there has to be a better way.

Thanks,
Padarick
 
Padarick said:
I have a form with a button that calls a delete macro,
runs a loop to add data to the table, then opens a report to
display/print the data.

It seems to be displaying the report without the data even thought the
data is in the table.
If I run the report outside of this routine it shows the data.

It is as if the code is executing out of order.
I have tried showallrecords and doevents.

This has come up over and over in Access 2003.
I have set timers to kick off the second half of the code after waiting
but there has to be a better way.


How are you inserting the records?

That behavior is normal(?) if you're using RunSQL with an
INSERT INTO query. I would not exprect that if you were
using the Execute method or even a recordset with AddNew.
 
What I am trying to do is get values from a listbox into a table so I can
print them out. The values are created on the fly and not with a query.
Thanks,

Code is as follows:

Private Sub BPrintItemlist_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery "Listbox Values - DEL"
DoCmd.SetWarnings True

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source = " &
ConDataPath
RSTemp.Open "[Listbox Values]", cnn1, adOpenKeyset, adLockOptimistic
With RSTemp
For TInt = 0 To Me.LBItems.ListCount - 1
.AddNew
!field1 = Me.LBItems.Column(0, TInt)
!field2 = Me.LBItems.Column(1, TInt)
!field3 = Me.LBItems.Column(2, TInt)
.Update
Next TInt
End With

RSTemp.Close
Set RSTemp = Nothing
cnn.Close
Set cnn = Nothing

DoCmd.ShowAllRecords
DoEvents

stDocName = "Analysis - Item List - RPT"
DoCmd.OpenReport stDocName, acPreview
End Sub
 
Whoops, I was unaware that you are using ADO and am not
qualified to discuss its timing issues.

I suggest that you repost this question stating your
environment up front so someone with ADO experience can
address it.
 
hi,

Padarick wrote
What I am trying to do is get values from a listbox into a table so I can
print them out. The values are created on the fly and not with a query.
Code is as follows:
As far as i can see, there are two possible problems.
Private Sub BPrintItemlist_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery "Listbox Values - DEL"
DoCmd.SetWarnings True
Replace the query with
CurrentDb.Execute "DELETE FROM ..", dbFailOnError
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source = " &
ConDataPath
RSTemp.Open "[Listbox Values]", cnn1, adOpenKeyset, adLockOptimistic
If ConDataPath is your current .mdb, replace cnn1 it with
CurrentProject.Connection
otherwise you get an isolation problem, because you have to connections
to your database.


mfG
--> stefan <--
 
Back
Top