Forum Discussion
Bill_Sterner
Jun 21, 2023Copper Contributor
Using gotoRecord,,acFirst and gotoRecord,,acnext
I am trying to run a "batch" type function by using "gotoRecord,,acFirst," and later after some other processing using "gotoRecord,,acNext" to get to the next record in the table, but the logic does ...
George_Hepworth
Jun 21, 2023Silver Contributor
Thank you.
That's unlike any VBA I'm familiar with, primarily because of the GoTo: labels instead of more commonly seen Recordset looping. It's an older programming method that has lost favor, although I suspect it probably does work.
The problem might be that in your code, you call several other routines, such as "rtn_Gun_Battery_1" which issue Me.Refresh commands. It is possible, I think, that this is causing the form to lose it's place in the current recordset and return to the first record every time. Without data to test against, of course, I can't be certain, but that's what I would try to eliminate as the first trouble-shooting step.
Others may spot additional potential problems.
That's unlike any VBA I'm familiar with, primarily because of the GoTo: labels instead of more commonly seen Recordset looping. It's an older programming method that has lost favor, although I suspect it probably does work.
The problem might be that in your code, you call several other routines, such as "rtn_Gun_Battery_1" which issue Me.Refresh commands. It is possible, I think, that this is causing the form to lose it's place in the current recordset and return to the first record every time. Without data to test against, of course, I can't be certain, but that's what I would try to eliminate as the first trouble-shooting step.
Others may spot additional potential problems.
Bill_Sterner
Jun 22, 2023Copper Contributor
I have stripped down the module and I still only get the first record in the table. I have included the current version below. The ""tbl_Ships" only has four records with the SH_RecordKey field being four unique ship names.
Option Compare Database
Private Sub Form_Load()
Dim SK5_Dbase As Database
Dim SK5_RecSet As Recordset
Dim RecKey As String
Set SK5_Dbase = CurrentDb
Set SK5_RecSet = SK5_Dbase.OpenRecordset("tbl_Ships")
Do Until SK5_RecSet.EOF
RecKey = SH_RecordKey
SK5_RecSet.MoveNext
Loop
Form_Exit:
DoCmd.Close
End Sub
Option Compare Database
Private Sub Form_Load()
Dim SK5_Dbase As Database
Dim SK5_RecSet As Recordset
Dim RecKey As String
Set SK5_Dbase = CurrentDb
Set SK5_RecSet = SK5_Dbase.OpenRecordset("tbl_Ships")
Do Until SK5_RecSet.EOF
RecKey = SH_RecordKey
SK5_RecSet.MoveNext
Loop
Form_Exit:
DoCmd.Close
End Sub
- George_HepworthJun 22, 2023Silver ContributorHow do you determine that you "get only the first record"?
- Bill_SternerJun 22, 2023Copper ContributorNote the first instruction after the DO UNTIL. I run with debug and displayed the SH_RecordKey field which displayed the key to the first record only each time. The logic did recognize the EOF condition and reacted correctly.
- George_HepworthJun 22, 2023Silver ContributorI think you might get the result you want if you use the value of SH_RecordKey from the recordset, rather than from the form's bound recordsource.
RecKey = SK5_RecSet!SH_RecordKey