I'm having some trouble with the code on this form - it's intended to increment the grades of all the students in the database.
If I open the form in design view and then switch to normal view it runs fine. If I double click it directly, however, it throws this error:
Runtime Error '2046'
The command or action 'GoToRecord' isn't available now.
When I debug the main loop in the code has always worked fine a few times before crashing.
The crash occurs on line 11.
Can anyone throw any light on the situation? -
Private Sub Form_Open(Cancel As Integer)
-
-
'Ups the grades of all students
-
-
'count records
-
Dim recordCount As Integer
-
recordCount = DCount("[ID]", "tblStudents")
-
DoCmd.GoToRecord acDataForm, "frmGradeUpdater", acGoTo, 1
-
-
For a = 1 To recordCount
-
DoCmd.GoToRecord acDataForm, "frmGradeUpdater", acGoTo, a
-
If Form_frmGradeUpdater.chkAlumni.Value = "0" Then GradeUp
-
Next a
-
-
Form_frmKeyData.flgUpdated = -1
-
DoCmd.Close
-
End Sub
-
-
Private Function GradeUp()
-
-
Dim maxGrade As Integer
-
maxGrade = Form_frmKeyData.cmbHighestGrade.Value
-
-
Dim response As String 'for alumni question
-
-
'check if the grade value is null, and throw up a warning message if so.
-
If (IsNull(Form_frmGradeUpdater.Grade.Value)) Then
-
MsgBox ("No grade data for: " & Form_frmGradeUpdater.txtForename.Value & " " & Form_frmGradeUpdater.txtSurname.Value)
-
Exit Function
-
End If
-
-
Dim currentGrade As String
-
currentGrade = Form_frmGradeUpdater.Grade.Value
-
-
Dim nameStore As String
-
nameStore = (Form_frmGradeUpdater.txtForename.Value & " " & Form_frmGradeUpdater.txtSurname.Value)
-
If currentGrade = "Grade 8" Then
-
If maxGrade = 8 Then
-
response = MsgBox("Should " & nameStore & " become an alumni student?", vbYesNo)
-
If response = 6 Then Form_frmGradeUpdater.chkAlumni = -1
-
End If
-
currentGrade = "Grade 9"
-
End If
-
If currentGrade = "Grade 7" Then currentGrade = "Grade 8"
-
If currentGrade = "Grade 6" Then currentGrade = "Grade 7"
-
If currentGrade = "Grade 5" Then currentGrade = "Grade 6"
-
If currentGrade = "Grade 4" Then currentGrade = "Grade 5"
-
If currentGrade = "Grade 3" Then currentGrade = "Grade 4"
-
If currentGrade = "Grade 2" Then currentGrade = "Grade 3"
-
If currentGrade = "Grade 1" Then currentGrade = "Grade 2"
-
If currentGrade = "Kindergarten" Then currentGrade = "Grade 1"
-
If currentGrade = "Preschool" Then currentGrade = "Kindergarten"
-
-
Form_frmGradeUpdater.Grade.Value = currentGrade
-
Exit Function
-
End Function
-
-
7 3155 ADezii 8,834
Recognized Expert Expert
I'm having some trouble with the code on this form - it's intended to increment the grades of all the students in the database.
If I open the form in design view and then switch to normal view it runs fine. If I double click it directly, however, it throws this error:
Runtime Error '2046'
The command or action 'GoToRecord' isn't available now.
When I debug the main loop in the code has always worked fine a few times before crashing.
The crash occurs on line 11.
Can anyone throw any light on the situation? -
Private Sub Form_Open(Cancel As Integer)
-
-
'Ups the grades of all students
-
-
'count records
-
Dim recordCount As Integer
-
recordCount = DCount("[ID]", "tblStudents")
-
DoCmd.GoToRecord acDataForm, "frmGradeUpdater", acGoTo, 1
-
-
For a = 1 To recordCount
-
DoCmd.GoToRecord acDataForm, "frmGradeUpdater", acGoTo, a
-
If Form_frmGradeUpdater.chkAlumni.Value = "0" Then GradeUp
-
Next a
-
-
Form_frmKeyData.flgUpdated = -1
-
DoCmd.Close
-
End Sub
-
-
Private Function GradeUp()
-
-
Dim maxGrade As Integer
-
maxGrade = Form_frmKeyData.cmbHighestGrade.Value
-
-
Dim response As String 'for alumni question
-
-
'check if the grade value is null, and throw up a warning message if so.
-
If (IsNull(Form_frmGradeUpdater.Grade.Value)) Then
-
MsgBox ("No grade data for: " & Form_frmGradeUpdater.txtForename.Value & " " & Form_frmGradeUpdater.txtSurname.Value)
-
Exit Function
-
End If
-
-
Dim currentGrade As String
-
currentGrade = Form_frmGradeUpdater.Grade.Value
-
-
Dim nameStore As String
-
nameStore = (Form_frmGradeUpdater.txtForename.Value & " " & Form_frmGradeUpdater.txtSurname.Value)
-
If currentGrade = "Grade 8" Then
-
If maxGrade = 8 Then
-
response = MsgBox("Should " & nameStore & " become an alumni student?", vbYesNo)
-
If response = 6 Then Form_frmGradeUpdater.chkAlumni = -1
-
End If
-
currentGrade = "Grade 9"
-
End If
-
If currentGrade = "Grade 7" Then currentGrade = "Grade 8"
-
If currentGrade = "Grade 6" Then currentGrade = "Grade 7"
-
If currentGrade = "Grade 5" Then currentGrade = "Grade 6"
-
If currentGrade = "Grade 4" Then currentGrade = "Grade 5"
-
If currentGrade = "Grade 3" Then currentGrade = "Grade 4"
-
If currentGrade = "Grade 2" Then currentGrade = "Grade 3"
-
If currentGrade = "Grade 1" Then currentGrade = "Grade 2"
-
If currentGrade = "Kindergarten" Then currentGrade = "Grade 1"
-
If currentGrade = "Preschool" Then currentGrade = "Kindergarten"
-
-
Form_frmGradeUpdater.Grade.Value = currentGrade
-
Exit Function
-
End Function
-
-
I can honestly say that I would not recommend this logic for updating Student's Grades, but it should, nonetheless, work regardless of the manner in which the Form is opened. Would you be able to send me the Database as an E-Mail Attachment, I would be more than happy to have a look at it. Currently, I do not have an explanation as to why this Error would occur only for a Form Dbl-Click.
mshmyob 904
Recognized Expert Contributor
I have found that Double clicking on the form and just switching back and forth between Form/Design view seems to always work a little differently depending on what you have done to the data.
RecordCount method should be avoided in my opinion all all costs. You might just consider using a MOVEFIRST and then MOVENEXT to cycle and just stop when eof.
I've played a little, and found that the form doesn't crash when opened from a module (as in normal use) so I'm going to leave the problem for now, thanks.
ADezii: Thanks for the offer, but I can't really email it out at this stage, I don't think my employers would like it :-)
mshmyob: thanks, I'll try doing that in future. Is RecordCount buggy? Are there other methods I should be avoiding that can cause similar errors?
ADezii 8,834
Recognized Expert Expert
I have found that Double clicking on the form and just switching back and forth between Form/Design view seems to always work a little differently depending on what you have done to the data.
RecordCount method should be avoided in my opinion all all costs. You might just consider using a MOVEFIRST and then MOVENEXT to cycle and just stop when eof.
Hello msymyob, I'm a little confused about your point on RecordCount. In the current code context, it, (recordCount), is used as an Integer Variable as referenced in Lines 6 and 7, and has no relation to either the DAO or ADO Property (RecordCount) whatsoever. Probably just getting old and missing something as usual. (LOL).
mshmyob 904
Recognized Expert Contributor
It seems to be a known bug. MS suggests putting in a module - but you already figured that out. You could also just put it under a button click event.
or
Changing your for next statement to be -
for a = 1 to (recordcount-2)
-
seems to make everything work also.
I've played a little, and found that the form doesn't crash when opened from a module (as in normal use) so I'm going to leave the problem for now, thanks.
ADezii: Thanks for the offer, but I can't really email it out at this stage, I don't think my employers would like it :-)
mshmyob: thanks, I'll try doing that in future. Is RecordCount buggy? Are there other methods I should be avoiding that can cause similar errors?
mshmyob 904
Recognized Expert Contributor
Not you ADezi it was my mistake. Must be my new laser surgery or I'm getting 2 old.
Hello msymyob, I'm a little confused about your point on RecordCount. In the current code context, it, (recordCount), is used as an Integer Variable as referenced in Lines 6 and 7, and has no relation to either the DAO or ADO Property (RecordCount) whatsoever. Probably just getting old and missing something as usual. (LOL).
ADezii 8,834
Recognized Expert Expert
Not you ADezi it was my mistake. Must be my new laser surgery or I'm getting 2 old.
BTW, congratulations again on joining the Team, I know you'll be a fine addition!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: swathky |
last post by:
I've tried mutiple things but no go -- (sorry this is so long)
I'm collecting a 5 digit number in an input box function and all works
fine until a number is passed that doesn't exist in the...
|
by: ann |
last post by:
Hi,
I am trying to add an ActiveX control on my ASP.NET web
form (the language for code behind is C#). I have some
client-side vbscript to handle events from the html input
buttons. In the...
|
by: g_man |
last post by:
I am trying trap Runtime error 3022 (duplicates) in the click event of
a command button that closes the form. I have code in the Form_Error
event that does a good job of providing a more meaningful...
|
by: John |
last post by:
Hi Everyone,
I'm having this extremely annoying problem with Internet Explorer 6,
giving me an error message saying "unknown runtime error" whenever I
try to alter the contents of a <divelement...
|
by: ruvi |
last post by:
I am getting runtime error 3021 - Either EOF or BOF is true or the current record has been deleted.....
I have 2 combo boxes in a form- One for the client and the other for the project.
When the...
| |
by: =?Utf-8?B?UkJlbGw=?= |
last post by:
I have a VB .NET app that I've been working on for quite some time. The app
has been working fine with no problems. I have recently been charged with
Internationalizing the app. Since I have never...
|
by: surja |
last post by:
Hi,
I have written a code to download images from a server end desktop,
but while running the code ,WTK is showing a runtime error " Create image from Byte array
Uncaught exception...
|
by: Jim Armstrong |
last post by:
Hello all -
This is driving me crazy. I have a table called tblClients - very
simple, has the following fields:
taxID (PK)
ClientName
SalesName
The main form of my application allows a...
|
by: morrisqueto |
last post by:
Hello,
One of my websites just started sending a new rare error. The site has been working for almost 2 years without trouble, but today morning started giving away this error in all my views.
...
|
by: suganya |
last post by:
Hi
Some professionals already has developed the project using menu. In my company, they have given me task to clear the error in that. It is a script file named as "menubarAPI4.js" which is kept...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |