Cannot go to specified record in new MS Access version

fluidmind1984

New member
Local time
Today, 16:09
Joined
May 17, 2015
Messages
2
Dear all,

I have a strange problem. 10 years ago I wrote the script below and it has always worked perfectly. Now, I have just updated to a new version of MS Access, and I suddenly get the error "Cannot go to the specified record" after going to the first post. Any idea why, and can anyone help with specific code examples (cause I'm a true rookie at this :-))?

John

Private Sub okknap_Click()
On Error GoTo Err_okknap_Click
DoCmd.SetWarnings False

'Gå til første post

DoCmd.GoToRecord , , acFirst

'Set controllerras til controllerrasquery

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL1 As String

Set dbs = CurrentDb()

strSQL1 = "SELECT * FROM stats"

Set rst = dbs.OpenRecordset(strSQL1, dbOpenSnapshot)


With rst
Do While Not rst.EOF

If spillerID <> "" Then
controllerras = controllerrasquery
DoCmd.GoToRecord , , acNext
End If
.MoveNext
Loop
End With
 
Dear all,

I have a strange problem. 10 years ago ...
No it is strange - you may expect that newer versions are more intolerant of bad programming behave.
Please explain what you expect the code to do?
Because the code does not show if there are variables, fields in the recordset, or controls on the form there is referred to.
Example: What is spillerID, is it a variable, a field in the recordset, or control on the form?
And so on in the whole code, there are no references to what!
 
Last edited:
Please explain what you expect the code to do?
I agree with JHB!

The culprit is this line:
Code:
DoCmd.GoToRecord , , acNext
Without knowing what you're trying to achieve (like JHB exclaimed), we can't give any concrete answers.
 
Dear JHB & vbaInet,

Thanks for taking the time to respond and please excuse the lack of information. I use Access at a fair level, but when it comes to vba-programming, I am really not that experienced. But let me try to explain a little more:

The form lists a number of basketball players (ID, name) with blank fields to enter their stats in the particular game (points, rebounds, assists, blocks, steals). Each line also contains a field (controllerrasquery) where I can indicate if the individual player plays for the home team "-1" or the away team "0". All these fields are created as text-fields that I can go through using the tab-key.

Imagine that after a game, this stat-sheet is filled in, and when pressing the okay button, I want the underlying table "stats" containing all these statlines (but with empty numbers) updated with the home/away value entered in the form (the other stats are updated later). Specifically, the text box value "controllerrasquery" should replaces the blank value in the "controllerras" column in the "stats" table. This should be repeated for each post in the form before moving on. And this is what used to happen when I pressed the OK button.

"SpillerID" refers to another text-field value in an open form, where all the players are loaded before being imported in the current statsheet form (had to divide it into two steps since I am a rookie :-)).

Hope this makes sense... Thanks for your patience.

J
 
I would use an update query instead of what you've.
Only for clarifying:
If you refer to a control on a form, use Me in front of it, like below.
Code:
If [B][COLOR=Red]Me.[/COLOR][/B]spillerID <> "" Then
[COLOR=Red][B]  Me.[/B][/COLOR]controllerras = controllerrasquery
 
Naming variables and objects using mixed case (like Me.ControllerRas ...) has the advantage than when you type the variable in lower case, the compiler will immediately convert it to the original case - if it finds it.

This means that all names that remain in lower case are misspelled - and that is a really good free and immediate check. Alt this provided you have followed the recommended practice and have

Option Explicit

at the top of all your code modules.
 

Users who are viewing this thread

Back
Top Bottom