473,395 Members | 2,079 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,395 software developers and data experts.

Error with custom navigation record count

374 256MB
I use the following code to add the number of records in to my custom navigation within my access database. A simple "Cost x of y" in my sub form that allows me to add costs to a particular activity, so users know how many have been added to that particular activity so far etc.

I also use the same code within my main form navigation to display the current record "x of y" for the activities.

I have changed the declared variables and ensured there is no conflict in other areas by simply adding a 2 to the end for example rst2 in my sub form and rst in my main form.

The problem I am having is when I load up my main form and navigate to the last record, which should then create a blank new record I get an error in the following code which is attached to my sub form navigation (subfrmCosts):

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. 'Provide record counter for costs
  3. Dim rst2 As DAO.Recordset
  4. Dim lngCount2 As Long
  5.  
  6. Set rst2 = Me.RecordsetClone
  7.  
  8. With rst2
  9. .MoveFirst
  10. .MoveLast
  11. lngCount2 = .RecordCount
  12. End With
  13.  
  14. 'Show the results of the count
  15.  
  16. If Me.CurrentRecord > lngCount2 Then
  17. Me.txtCostRecNo = "New Cost"
  18.  
  19. Else
  20.  
  21. Me.txtCostRecNo = "Cost " & Me.CurrentRecord & " of " & lngCount2
  22. End If
  23.  
  24.  
  25. End Sub
Similar code to the above works fine in my main form (with the 2's removed to ensure unique names to variables etc), just not in the sub form controls.

The error is highlighted on the line .MoveLast and I get an alert showing "Run time error 3021" No current record.

I thought I would have stopped this error occuring by adding the if function so that it would display "New Cost" however this doesnt seem to be working, eventhough yesterday everything was running fine.

Any help appreciated thanks.
Jun 16 '10 #1
2 2688
munkee
374 256MB
Just a quick follow up, when I disable the code within the subform the main form code works perfectly fine.

When I re-enable the code in the sub form. The Sub form numbers work correctly however if I navigate to the last record within the main form instead of displaying "New Record" I get the error. Which highlights the sub form code, not the main form code.
Jun 16 '10 #2
munkee
374 256MB
Managed to do some research and messed around with the code to get it working now:

Expand|Select|Wrap|Line Numbers
  1. Public Sub Form_Current()
  2. 'Provide record counter for costs
  3. Dim rst2 As DAO.Recordset
  4. Dim lngCount2 As Long
  5.  
  6. Set rst2 = Me.RecordsetClone
  7.  
  8. With rst2
  9. If .RecordCount > 0 Then
  10. .MoveLast
  11. .MoveFirst
  12. End If
  13.  
  14. 'Show the results of the count
  15. If Me.CurrentRecord > .RecordCount Then
  16.  
  17. Me.txtCostRecNo = "New Cost Record"
  18.  
  19. Else
  20.  
  21. Me.txtCostRecNo = "Cost " & Me.CurrentRecord & " of " & .RecordCount
  22.  
  23. End If
  24. End With
  25. End Sub
Used similar code for the main form also and it works fine now.
Jun 16 '10 #3

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

Similar topics

6
by: Hari Om | last post by:
Here are the details of my error log files: I execute the command and get following message at console: ---------------------------------------------------------------------- ../sqlldr...
3
by: thomasp | last post by:
I am trying to get a record count of a PHP query on a MS Acess database using ODBC with a DSN for MS ACCESS connection. I got this code from the PHP manual user notes. It seems to return the...
1
by: Robert Neville | last post by:
I am having some trouble with some old code revolving around custom form navigation buttons. My main form has a sub-form with these custom navigation buttons. In other words, the code should be...
1
by: Ryan | last post by:
I've got a problem I have't run up against before. I generally test for an empty recordset using BOF and EOF. Today, for the first time I ran into a problem where my recordset shows BOF and EOF =...
1
by: Henry Stockbridge | last post by:
Hi, I am doing database documentation and run the procedure below to list the record count for each table in the database. The results in the immediate window only a partial listing of tables. ...
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 =...
1
by: darrel | last post by:
I'm trying to whip up a fancy repeater control that will put records into a two-column table for me. This is how I envision it working: itemtemplate if record count = odd then write out the...
4
by: darrel | last post by:
I have a repeater that I'd like to apply some logic to, namly highlighting the top few items in the repeater. To do this, I need to determine the record count. I've tried this: <% dim...
7
by: Mike | last post by:
I have a form where I have turned off the default navigation buttons. I then created my own. This works fine. The only questions that I have is on the default navigation buttons it shows total...
4
by: Peter W Johnson | last post by:
Hi guys, I have a problem with a datagrid record count. Here is the code:- <snip> Public Class frmMerchantDeposit Inherits System.Windows.Forms.Form Dim myconnection As New...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.