473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Error message ‘3021’ when I use a sub form with a Record Counter x

Hello All,
I am having a little trouble with my database. The Database has a parent table with 5 or 6 children tables in it they are linked by a common id filed.

The problem is that the children tables use a VBA to display there Record number in a text box. The code works fine when they are displayed alone when I do not have them displayed in the main or parent table. The problem I get is "run-time error '3021' "


I am ataching two version of code:

Here is the first version of code I put in to the children's table under forms, events, form_Current.

The output is displeased in a unbound text box called txtRecordNo.


Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Current()
  3.  
  4. Dim rst As DAO.Recordset
  5. Dim lngCount As Long
  6.  
  7. Set rst = Me.RecordsetClone
  8.  
  9. With rst
  10. .MoveFirst
  11. .MoveLast
  12. lngCount = .RecordCount
  13. End With
  14.  
  15.  
  16. Me.txtRecordNo = "Record " & Me.CurrentRecord & " of " & lngCount
  17.  
  18. End Sub
  19.  

Hear is the secend version of code it is linked by in unbound label called RecNum:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Option Compare Database
  3. Option Explicit
  4. Dim Records As DAO.Recordset
  5. Dim TotalRecords
  6.  
  7. Private Sub Form_Load()
  8. Set Records = Me.RecordsetClone
  9. Records.MoveLast
  10. TotalRecords = Records.RecordCount
  11. End Sub
  12.  
  13. Private Sub Form_BeforeInsert(Cancel As Integer)
  14. Me![RecNum].Caption = TotalRecords + 1 & " pending..."
  15. End Sub
  16.  
  17. Private Sub Form_AfterInsert()
  18. Records.MoveLast
  19. TotalRecords = Records.RecordCount
  20. End Sub
  21.  
  22. Private Sub Form_Current()
  23. If Not Me.NewRecord Then
  24. Records.Bookmark = Me.Bookmark
  25. Me![RecNum].Caption = "Record " & _
  26. Records.AbsolutePosition + 1 & " of " & _
  27. TotalRecords
  28. Else
  29. Me![RecNum].Caption = "New Record"
  30. End If
  31. End Sub 
  32.  
I do not know how to deal with a run-time error '3021'. So if some one has a suggestion on how do get this code to work or a different way of displaying the records in a sub form.
Feb 4 '09 #1
8 2581
ChipR
1,287 Expert 1GB
When working with a recordset, you need to check for records.BOF or records.EOF. If you are .BOF (before beginning or something) there may be no records at all, and if you are .EOF you are past the end of the records. Either way, there is no current record to do operations on, hence the error message.
Feb 5 '09 #2
Thank you ChipR,

Is there a way to display a record counter in a text box or label that is in a sub form?
Feb 6 '09 #3
ChipR
1,287 Expert 1GB
Do you mean a count of all the records shown in the subform? If so, you can put a text box in the subform's Form Footer and make it

=Count(FieldName)

Where FieldName is any field that is shown in the subform for each record.
Feb 6 '09 #4
I tried to put =[CurrentRecord]

to cont the current record and

=RecordsetClone.Recordcount
to count the total records
I put both of these 'code' in the control source of the textbox. They work on my pc but not any other pc I tried. I get a #name in the textbox. However the code in VBA works in other pc when I am not running them in a sub form.
Feb 6 '09 #5
ChipR
1,287 Expert 1GB
Can you turn on Navigation Buttons in the subform's properties?
Feb 6 '09 #6
Yes but I am trying to avoid that because some of the form I are very long and the id field is on top.
Feb 6 '09 #7
ChipR
1,287 Expert 1GB
Did you try my suggestion in post #4 in the subform header?
Feb 6 '09 #8
yes thank you Chip R post #4 works in other pc
Feb 6 '09 #9

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

Similar topics

1
by: Colin Graham | last post by:
I am writing this piece of code to show the previous record on a control on the form but i keep getting the error message "Error 3021 no current record " and the line marked *** gets highlighted. I...
9
by: Robert Wing | last post by:
I support an MS Access application in which errors are trapped using the On Error statement. Just recently, the users of this system have experienced run-time error number 3021 on a random basis. ...
3
by: WindAndWaves | last post by:
I am writing error handling procedures at the moment. Here are some questions: 1. Can you write a procedure that picks up any error and deals with it no matter where it happens in the database?...
2
by: Polly | last post by:
I'm trying to write the results of a query, a name, ID number, and date out to a notepad .txt file to print on a "legacy" printer. I get the output from the first 2 "write" lines over the...
3
by: windandwaves | last post by:
Hi, I am trying to make errors a bit more meaningful for my users. I am trying to fix error 3201 where there is a missing field in a form. If I do not do any error trapping, then I get ...
2
by: Robert | last post by:
I have a label on my form lblCount and the following code in my form for displaying a record count: Private Sub Form_Current() Me.RecordsetClone.Bookmark = Me.Bookmark Me!lblCount.Caption =...
7
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...
5
by: prakashwadhwani | last post by:
The Delete Event/Proc & "Save_Fields_In_Form_Header" Event/Proc in my form were working perfectly. However, after I added a call to the "Save_Fields_In_Form_Header" Event/Proc in the...
0
by: bssandeshbs | last post by:
I am developing a Address Book Database Project using Visual Basic 6... When i click the delete button the data does'nt get deleted in the FrontEnd ..But it gets deleted in Database when we see in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.