Current Record, et al

pullmyefinger

Registered User.
Local time
Yesterday, 20:23
Joined
Feb 26, 2011
Messages
37
Sub CurrentFormRecord(frm As Form)
Dim lngrecordnum As Long

lngrecordnum = frm.CurrentRecord
End Sub

=======================================

The code above is supposedly a way to store the current record of a table tied to a Form???

1. what the heck is (frm as Form) in the Sub? what form?

2. if I have a Form called X and a Table called Y that is tied to the Form, how do I integrate these in the example above?? Do I have to call this Sub every time I change records????

3. also have a command button that deletes records out of table Y in form X. When I delete a record(s), WHAT do I have to do to Correctly Update the number of Records in the Y table?? (I know there is a dcount() Fn, and a .movelast and other stuff


This is all I have to do to have this thing done. Hope someone can Help..
 
Last edited:
The Sub is designed to store the index number of the current record or the form. However as shown it doesn't actually do anything useful. It stores the number in a private variable which will be lost when the sub is exited.

What are you planning to do with the index of the current record?

"frm As Form" is an argument of the Sub. When the sub is called a reference to the form is included for the sub to work with.

eg
CurrentFormRecord Forms!formname
CurrentFormRecord Me!subformcontrol.Form

The reference is passed and used in the code wherever the "frm" term appears.

Generally the best way to show the number of records in the Recordset of a form is to place a textbox in the footer or header with the ControlSource:
=Count(*)
 
All I wanted was to know how many records are in the table, including an updated number when any records are deleted. Someone told me there is a button wizard that does that for you but i don't have it and can't find it anywhere in 2003.

This is one of the two button's code:

Private Sub NextRecBtn_Click()

Dim currentrec, lastrec, numrows As Long
numrows = DCount("*", "EQPT")
lastrec = numrows

THE COMMENTED LINE BELOW IS WHY I ASKED ABOUT 'FRM'; DON'T UNDERSTAND IT AT ALL.

ALL I NEED IS TO BE ABLE TO COMPARE THE CURRENT FORM RECORD TO 1 OR
THE NUMBER OF RECORDS IN THE TABLE THAT IS ATTACHED TO THE FORM AND DO "...ENABLED=FALSE" FOR EITHER/BOTH BUTTONS.

'currentrec = frm.CurrentRecord

If numrows = 1 Then

Me.NextRecBtn.Enabled = False
ElseIf currentrec = numrows Then

Me.NextRecBtn.Enabled = False

Else
Me.NextRecBtn.Enabled = True
DoCmd.RunCommand acCmdRecordsGoToNext
End If
End Sub



I would appreciate any help you could give me; I want this thing done. Thank You.
 
ok, then what do I use in the Next Record and Previous Record buttons to get the correct, current record in the table serving the Form?? This needs to also update the correct number of records in the table after Deleting a record when I push the Delete command button..
 
Sub CurrentFormRecord(frm As Form)
Dim lngrecordnum As Long

lngrecordnum = frm.CurrentRecord
End Sub

=======================================

The code above is supposedly a way to store the current record of a table tied to a Form???

1. what the heck is (frm as Form) in the Sub? what form?
This will get you the current record (as it's written)
Code:
[B]=Form.CurrentRecord[/B]

2. if I have a Form called X and a Table called Y that is tied to the Form, how do I integrate these in the example above?? Do I have to call this Sub every time I change records????
As Galaxiom mentiond, =Count(*) will get you the count of records so combine this idea and the one above to get X of Y.

3. also have a command button that deletes records out of table Y in form X. When I delete a record(s), WHAT do I have to do to Correctly Update the number of Records in the Y table?? (I know there is a dcount() Fn, and a .movelast and other stuff
With the ideas presented above you won't need to do anything as that's already handled by Access. However, if you find that it's not automatically updating after a record was deleted or added, put Me.Requery in the After Del Confirm and After Insert events of the form.

All I wanted was to know how many records are in the table, including an updated number when any records are deleted. Someone told me there is a button wizard that does that for you but i don't have it and can't find it anywhere in 2003.
Someone told you that the wizard has Next Record and Previous Record buttons already coded, not [Current Record] of [Count].

With regards moving next or previous, the code presented by missinglinq (#3) in your other thread does just that:

http://www.access-programmers.co.uk/forums/showthread.php?t=207238
 

Users who are viewing this thread

Back
Top Bottom