BobbyGraves
Registered User.
- Local time
- Today, 05:44
- Joined
- Nov 7, 2012
- Messages
- 15
Hi, I'm just getting back into Access programming after a very long time (not that I was ever an expert). I'm using Access 2007 on a Windows 7 Pro installation.
First off, let me just say I have tried to look for solutions to this problem. I see many threads with all the right keywords, but they all seem to be complicated solutions to more complicated problems. My requirement is simple and, I would expect, common. I just can't believe a program would be allowed out the door that didn't have an elegant solution for it.
At this point, all my app does is clear out a table for which a datasheet is linked. I'm having the darndest time getting the datasheet not to show a bunch of "#Deleted" after the table is cleared and the datasheet is requeried. It seems to take a while before I can call that method and have it work properly. I've made an ugly work-around hack that sort of gets around it. It's just a wait-type function that puts execution into a loop for 5 seconds (anything less rarely works). At that point, the Requery method does its job. Here it is:
-----------------------------------------------
Option Compare Database
Public dbSpecReview As Database
Public rsTravOutQuery As DAO.Recordset
-----------------------------------------------
Private Sub Form_Load()
Set dbSpecReview = OpenDatabase("C:\MyFolder\MyDatabaseName.mdb")
'clear out the table
ClearQueryTable
'work-around hack
WaitForAccess 5
'requery datasheet (source = the table that was cleared)
Me.TravOut_Datasheet.Requery
End Sub
-----------------------------------------------
Public Sub ClearQueryTable()
Set rsTravOutQuery = dbSpecReview.OpenRecordset("MyTableName", dbOpenTable)
Do While Not rsTravOutQuery.EOF
rsTravOutQuery.Delete
rsTravOutQuery.MoveNext
Loop
End Sub
-----------------------------------------------
Public Sub WaitForAccess(iSeconds As Integer)
Dim tNow As Date
Dim tThen As Date
tNow = Time
tThen = DateAdd("s", iSeconds, Time)
Do Until tNow >= tThen
tNow = Time
Loop
End Sub
-----------------------------------------------
Pretty simple, right? Here are my questions:
1) Is there something obvious that I'm missing? By the way, I have tried resetting the source of the datasheet before the Requery call, as one post I read suggested.
2) I take it code execution does not pause while the record is being updated? Is there any event or mechanism I can use that will allow me to properly time the Requery method? My work-around hack lacks reliability unless I set it to a crazy-high wait period.
3) Would you advise me to go ADO instead of DAO? I gather it's faster. Does it provide a method, event or some other kind of mechanism to make a more elegant solution?
Thank you kindly for your consideration.
-Bobby
First off, let me just say I have tried to look for solutions to this problem. I see many threads with all the right keywords, but they all seem to be complicated solutions to more complicated problems. My requirement is simple and, I would expect, common. I just can't believe a program would be allowed out the door that didn't have an elegant solution for it.
At this point, all my app does is clear out a table for which a datasheet is linked. I'm having the darndest time getting the datasheet not to show a bunch of "#Deleted" after the table is cleared and the datasheet is requeried. It seems to take a while before I can call that method and have it work properly. I've made an ugly work-around hack that sort of gets around it. It's just a wait-type function that puts execution into a loop for 5 seconds (anything less rarely works). At that point, the Requery method does its job. Here it is:
-----------------------------------------------
Option Compare Database
Public dbSpecReview As Database
Public rsTravOutQuery As DAO.Recordset
-----------------------------------------------
Private Sub Form_Load()
Set dbSpecReview = OpenDatabase("C:\MyFolder\MyDatabaseName.mdb")
'clear out the table
ClearQueryTable
'work-around hack
WaitForAccess 5
'requery datasheet (source = the table that was cleared)
Me.TravOut_Datasheet.Requery
End Sub
-----------------------------------------------
Public Sub ClearQueryTable()
Set rsTravOutQuery = dbSpecReview.OpenRecordset("MyTableName", dbOpenTable)
Do While Not rsTravOutQuery.EOF
rsTravOutQuery.Delete
rsTravOutQuery.MoveNext
Loop
End Sub
-----------------------------------------------
Public Sub WaitForAccess(iSeconds As Integer)
Dim tNow As Date
Dim tThen As Date
tNow = Time
tThen = DateAdd("s", iSeconds, Time)
Do Until tNow >= tThen
tNow = Time
Loop
End Sub
-----------------------------------------------
Pretty simple, right? Here are my questions:
1) Is there something obvious that I'm missing? By the way, I have tried resetting the source of the datasheet before the Requery call, as one post I read suggested.
2) I take it code execution does not pause while the record is being updated? Is there any event or mechanism I can use that will allow me to properly time the Requery method? My work-around hack lacks reliability unless I set it to a crazy-high wait period.
3) Would you advise me to go ADO instead of DAO? I gather it's faster. Does it provide a method, event or some other kind of mechanism to make a more elegant solution?
Thank you kindly for your consideration.
-Bobby