473,508 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Runtime error on form

20 New Member
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?

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.  
  3. 'Ups the grades of all students
  4.  
  5. 'count records
  6. Dim recordCount As Integer
  7. recordCount = DCount("[ID]", "tblStudents")
  8. DoCmd.GoToRecord acDataForm, "frmGradeUpdater", acGoTo, 1
  9.  
  10. For a = 1 To recordCount
  11. DoCmd.GoToRecord acDataForm, "frmGradeUpdater", acGoTo, a
  12. If Form_frmGradeUpdater.chkAlumni.Value = "0" Then GradeUp
  13. Next a
  14.  
  15. Form_frmKeyData.flgUpdated = -1
  16. DoCmd.Close
  17. End Sub
  18.  
  19. Private Function GradeUp()
  20.  
  21. Dim maxGrade As Integer
  22. maxGrade = Form_frmKeyData.cmbHighestGrade.Value
  23.  
  24. Dim response As String 'for alumni question
  25.  
  26. 'check if the grade value is null, and throw up a warning message if so.
  27. If (IsNull(Form_frmGradeUpdater.Grade.Value)) Then
  28.     MsgBox ("No grade data for: " & Form_frmGradeUpdater.txtForename.Value & " " & Form_frmGradeUpdater.txtSurname.Value)
  29.     Exit Function
  30. End If
  31.  
  32. Dim currentGrade As String
  33. currentGrade = Form_frmGradeUpdater.Grade.Value
  34.  
  35. Dim nameStore As String
  36. nameStore = (Form_frmGradeUpdater.txtForename.Value & " " & Form_frmGradeUpdater.txtSurname.Value)
  37. If currentGrade = "Grade 8" Then
  38.     If maxGrade = 8 Then
  39.      response = MsgBox("Should " & nameStore & " become an alumni student?", vbYesNo)
  40.      If response = 6 Then Form_frmGradeUpdater.chkAlumni = -1
  41.     End If
  42.     currentGrade = "Grade 9"
  43. End If
  44. If currentGrade = "Grade 7" Then currentGrade = "Grade 8"
  45. If currentGrade = "Grade 6" Then currentGrade = "Grade 7"
  46. If currentGrade = "Grade 5" Then currentGrade = "Grade 6"
  47. If currentGrade = "Grade 4" Then currentGrade = "Grade 5"
  48. If currentGrade = "Grade 3" Then currentGrade = "Grade 4"
  49. If currentGrade = "Grade 2" Then currentGrade = "Grade 3"
  50. If currentGrade = "Grade 1" Then currentGrade = "Grade 2"
  51. If currentGrade = "Kindergarten" Then currentGrade = "Grade 1"
  52. If currentGrade = "Preschool" Then currentGrade = "Kindergarten"
  53.  
  54. Form_frmGradeUpdater.Grade.Value = currentGrade
  55. Exit Function
  56. End Function
  57.  
  58.  
Feb 8 '08 #1
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?

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.  
  3. 'Ups the grades of all students
  4.  
  5. 'count records
  6. Dim recordCount As Integer
  7. recordCount = DCount("[ID]", "tblStudents")
  8. DoCmd.GoToRecord acDataForm, "frmGradeUpdater", acGoTo, 1
  9.  
  10. For a = 1 To recordCount
  11. DoCmd.GoToRecord acDataForm, "frmGradeUpdater", acGoTo, a
  12. If Form_frmGradeUpdater.chkAlumni.Value = "0" Then GradeUp
  13. Next a
  14.  
  15. Form_frmKeyData.flgUpdated = -1
  16. DoCmd.Close
  17. End Sub
  18.  
  19. Private Function GradeUp()
  20.  
  21. Dim maxGrade As Integer
  22. maxGrade = Form_frmKeyData.cmbHighestGrade.Value
  23.  
  24. Dim response As String 'for alumni question
  25.  
  26. 'check if the grade value is null, and throw up a warning message if so.
  27. If (IsNull(Form_frmGradeUpdater.Grade.Value)) Then
  28.     MsgBox ("No grade data for: " & Form_frmGradeUpdater.txtForename.Value & " " & Form_frmGradeUpdater.txtSurname.Value)
  29.     Exit Function
  30. End If
  31.  
  32. Dim currentGrade As String
  33. currentGrade = Form_frmGradeUpdater.Grade.Value
  34.  
  35. Dim nameStore As String
  36. nameStore = (Form_frmGradeUpdater.txtForename.Value & " " & Form_frmGradeUpdater.txtSurname.Value)
  37. If currentGrade = "Grade 8" Then
  38.     If maxGrade = 8 Then
  39.      response = MsgBox("Should " & nameStore & " become an alumni student?", vbYesNo)
  40.      If response = 6 Then Form_frmGradeUpdater.chkAlumni = -1
  41.     End If
  42.     currentGrade = "Grade 9"
  43. End If
  44. If currentGrade = "Grade 7" Then currentGrade = "Grade 8"
  45. If currentGrade = "Grade 6" Then currentGrade = "Grade 7"
  46. If currentGrade = "Grade 5" Then currentGrade = "Grade 6"
  47. If currentGrade = "Grade 4" Then currentGrade = "Grade 5"
  48. If currentGrade = "Grade 3" Then currentGrade = "Grade 4"
  49. If currentGrade = "Grade 2" Then currentGrade = "Grade 3"
  50. If currentGrade = "Grade 1" Then currentGrade = "Grade 2"
  51. If currentGrade = "Kindergarten" Then currentGrade = "Grade 1"
  52. If currentGrade = "Preschool" Then currentGrade = "Kindergarten"
  53.  
  54. Form_frmGradeUpdater.Grade.Value = currentGrade
  55. Exit Function
  56. End Function
  57.  
  58.  
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.
Feb 9 '08 #2
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.
Feb 9 '08 #3
JKoyis
20 New Member
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?
Feb 12 '08 #4
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).
Feb 12 '08 #5
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

Expand|Select|Wrap|Line Numbers
  1. for a = 1 to (recordcount-2)
  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?
Feb 12 '08 #6
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).
Feb 12 '08 #7
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!
Feb 12 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

8
5144
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...
0
4395
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...
8
13078
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...
7
37995
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...
7
31402
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...
0
1321
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...
4
1606
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...
3
5150
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...
1
3795
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. ...
3
8633
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...
0
7225
marktang
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,...
0
7124
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...
0
7326
Oralloy
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,...
0
7385
jinu1996
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...
1
7046
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...
1
5053
isladogs
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...
0
4707
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...
0
1558
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 ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.