|
-
Aug 11th, 2005, 09:29 AM
#1
Thread Starter
Junior Member
Simple Access
Whats the code to return the record number of the record you are currently viewing on a form?
-
Aug 11th, 2005, 11:20 AM
#2
Re: Simple Access
You can set a recordset object to your fors one and access the rs properties like so.
VB Code:
Dim oRs As Recordset
Set oRs = Me.Recordset
MsgBox oRs.RecordCount
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 11th, 2005, 01:54 PM
#3
Re: Simple Access
However (God I like that word )
It's not as simple as that.. AbsolutePosition and PercentPosition and all that... plus the recordset is opened in a Cache, great for small recordsets but a nightmare for a large table..
I can give you some code that you will be able to set the RecordSource of the form via SQL and a sequence number..
All you need is one unique field in the table/query and it will work everytime (and I'm not talking about just using the Autonumber...
VB Code:
SELECT *, DCount("RecNumber","TableName","RecNumber<" & [RecNumber])+1 AS SeqNr FROM [TableName];
Where RecNumber represents the primary key in the table.. you can then reference the SeqNr for your record count..
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Aug 11th, 2005, 01:59 PM
#4
Re: Simple Access
No, DCount is slow. If your Form already is opened then the recordset is already populated and set. Alll your doing is attaching a oRs recordset object to it to access the .RecordCoutn property. 
There is no need to perform a second call to the table delaying things twice as much.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 11th, 2005, 02:21 PM
#5
-
Aug 11th, 2005, 09:34 PM
#6
Re: Simple Access
Oh, record position and not count. Still you can use the .AbsolutePosition property of the rs to determine that, depending on how your cursor type, etc.
 Originally Posted by DK
Hmm.. Your sig needs a change RD.. 
What are you talking about?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 12th, 2005, 02:31 AM
#7
Re: Simple Access
 Originally Posted by RobDogg888
Oh, record position and not count. Still you can use the .AbsolutePosition property of the rs to determine that, depending on how your cursor type, etc.
Try again..
.AbsolutePosition +1 will do it, but when adding a new record this will state the recordcount until the new record is written.. mine doesn't..
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Aug 12th, 2005, 05:38 AM
#8
Thread Starter
Junior Member
Re: Simple Access
nice 1 guys, sounds like theres a bit of a battle going on but cheers for the info.
-
Aug 12th, 2005, 08:31 AM
#9
-
Aug 12th, 2005, 09:12 AM
#10
Thread Starter
Junior Member
Re: Simple Access
ok so i used your code from your example and changed it to
SELECT ContractDetails.*, DCount("ContractReference","ContractDetails","ContractReference<" & [ContractReference])+1 AS SeqNr
FROM ContractDetails;
//where ContractDetails is the name of my table and ContractReference is my primary key in that table
BUT i get "The expression you entered as a query parameter produced this error: 'The object doesn't contain the Automation object 'CON.''
-
Aug 12th, 2005, 09:20 AM
#11
Re: Simple Access
Just created a sample table matching your details above and also created a query with the SQL above and a form with the RecordSource set the same query.. I got no error..
This looks like it is something in your form that is causing the problem.. check your form's RecordSource to make sure that the SQL is not in quotes and is definately like what you have posted..
If it's not there then it must be a control..
Once you have changed the recordsource bring up the field list and check each control to match the fields.. the sequence (record count) number will be called SeqNr.
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Aug 12th, 2005, 10:33 AM
#12
Thread Starter
Junior Member
Re: Simple Access
ahhh its killin me, gonna take a rest for the weekend and have a look on Monday...Good effort mate, i've been doing it all day and reckon a bit of sleep will sort it out
-
Aug 12th, 2005, 10:44 AM
#13
Re: Simple Access
You could just upload an example of the DB in Zip format for us to take a look at..
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Aug 12th, 2005, 10:45 AM
#14
Re: Simple Access
 Originally Posted by dannymking
Try again..
.AbsolutePosition +1 will do it, but when adding a new record this will state the recordcount until the new record is written.. mine doesn't..
But thats the way Access Forms do it, by adding a new recordcount before its actually updated and saved to the table.
Sounds like this thread is about solved. Good work DMK.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|