Numbering records

T

Tara

I have a continuous subform and I'm trying to make each record displayed
numbered 1, 2, 3, etc. I personally see no use for that - at least in this
situation, but for whatever reason, the user would prefer it. So, I tried
using Stephen Lebans' RowNum solution (found here:
http://www.lebans.com/rownumber.htm
Thank you Stephen!) but the unbound text box on the subform shows #Name?
when the form is opened. Obviously I've done something wrong. I've been
*dabbling* in code for some time, but I'm still a newbie and am therefore
prone to many, many amatuerish mistakes. Here's the code:

'Copyright Stephen Lebans 1999
'May not be resold
'Please include my 1 line Copyright notice
'in your code if you use these functions

Public Function RowNum(frm As Form) As Variant
On Error GoTo Err_RowNum
'Purpose: Numbering the rows on a form.
'Usage: Text box with ControlSource of: =RowNum([Form])

With frm.RecordsetClone
.Bookmark = frm.Bookmark
RowNum = .AbsolutePosition + 1
End With

Exit_RowNum:
Exit Function

Err_RowNum:
If Err.Number <> 3021& Then 'Ignore "No bookmark" at new row.
Debug.Print "RowNum() error " & Err.Number & " - " & Err.Description
End If
RowNum = Null
Resume Exit_RowNum
End Function


What could the issue be? Thanks in advance!
 
R

ruralguy via AccessMonster.com

Hmm...that code is going to have a problem with a SubForm. Have you tried
modifying the code so it will run in your SubForm Class module? No need to
pass the Form object since you are within that form.
I have a continuous subform and I'm trying to make each record displayed
numbered 1, 2, 3, etc. I personally see no use for that - at least in this
situation, but for whatever reason, the user would prefer it. So, I tried
using Stephen Lebans' RowNum solution (found here:
http://www.lebans.com/rownumber.htm
Thank you Stephen!) but the unbound text box on the subform shows #Name?
when the form is opened. Obviously I've done something wrong. I've been
*dabbling* in code for some time, but I'm still a newbie and am therefore
prone to many, many amatuerish mistakes. Here's the code:

'Copyright Stephen Lebans 1999
'May not be resold
'Please include my 1 line Copyright notice
'in your code if you use these functions

Public Function RowNum(frm As Form) As Variant
On Error GoTo Err_RowNum
'Purpose: Numbering the rows on a form.
'Usage: Text box with ControlSource of: =RowNum([Form])

With frm.RecordsetClone
.Bookmark = frm.Bookmark
RowNum = .AbsolutePosition + 1
End With

Exit_RowNum:
Exit Function

Err_RowNum:
If Err.Number <> 3021& Then 'Ignore "No bookmark" at new row.
Debug.Print "RowNum() error " & Err.Number & " - " & Err.Description
End If
RowNum = Null
Resume Exit_RowNum
End Function

What could the issue be? Thanks in advance!
 
T

Tara

I'm not sure what you mean exactly. I'm an amatuer at coding. I can do
small things, but my overall knowledge is very limited. Would you be willing
to provide some more detail? I'd really appreciate any help you could offer.

ruralguy via AccessMonster.com said:
Hmm...that code is going to have a problem with a SubForm. Have you tried
modifying the code so it will run in your SubForm Class module? No need to
pass the Form object since you are within that form.
I have a continuous subform and I'm trying to make each record displayed
numbered 1, 2, 3, etc. I personally see no use for that - at least in this
situation, but for whatever reason, the user would prefer it. So, I tried
using Stephen Lebans' RowNum solution (found here:
http://www.lebans.com/rownumber.htm
Thank you Stephen!) but the unbound text box on the subform shows #Name?
when the form is opened. Obviously I've done something wrong. I've been
*dabbling* in code for some time, but I'm still a newbie and am therefore
prone to many, many amatuerish mistakes. Here's the code:

'Copyright Stephen Lebans 1999
'May not be resold
'Please include my 1 line Copyright notice
'in your code if you use these functions

Public Function RowNum(frm As Form) As Variant
On Error GoTo Err_RowNum
'Purpose: Numbering the rows on a form.
'Usage: Text box with ControlSource of: =RowNum([Form])

With frm.RecordsetClone
.Bookmark = frm.Bookmark
RowNum = .AbsolutePosition + 1
End With

Exit_RowNum:
Exit Function

Err_RowNum:
If Err.Number <> 3021& Then 'Ignore "No bookmark" at new row.
Debug.Print "RowNum() error " & Err.Number & " - " & Err.Description
End If
RowNum = Null
Resume Exit_RowNum
End Function

What could the issue be? Thanks in advance!
 
R

ruralguy via AccessMonster.com

Try something like this in the SubForm:


Public Function RowNum() As Variant
On Error GoTo Err_RowNum
'Purpose: Numbering the rows on a SubForm.

'Usage: SubForm Text box with ControlSource of: =RowNum()

RowNum = Me.Recordset.AbsolutePosition + 1

Exit_RowNum:
Exit Function

Err_RowNum:
Resume Exit_RowNum
End Function


I'm not sure what you mean exactly. I'm an amatuer at coding. I can do
small things, but my overall knowledge is very limited. Would you be willing
to provide some more detail? I'd really appreciate any help you could offer.
Hmm...that code is going to have a problem with a SubForm. Have you tried
modifying the code so it will run in your SubForm Class module? No need to
[quoted text clipped - 37 lines]
 
T

Tara

I'm getting closer, I think, but I'm still running into a problem somewhere.
It now shows 0 in the text box if there are no records in the subform, then
when I get to the first client with records, it shows 1. Unfortunately, it
shows 1 for each of the records, not just the first one. Also, if I then
move on to the next client's records, the text box displays 0 again,
regardless of whether or not there are any records to display in the subform.
I know I'm close, I just can't quite figure it out.

ruralguy via AccessMonster.com said:
Try something like this in the SubForm:


Public Function RowNum() As Variant
On Error GoTo Err_RowNum
'Purpose: Numbering the rows on a SubForm.

'Usage: SubForm Text box with ControlSource of: =RowNum()

RowNum = Me.Recordset.AbsolutePosition + 1

Exit_RowNum:
Exit Function

Err_RowNum:
Resume Exit_RowNum
End Function


I'm not sure what you mean exactly. I'm an amatuer at coding. I can do
small things, but my overall knowledge is very limited. Would you be willing
to provide some more detail? I'd really appreciate any help you could offer.
Hmm...that code is going to have a problem with a SubForm. Have you tried
modifying the code so it will run in your SubForm Class module? No need to
[quoted text clipped - 37 lines]
What could the issue be? Thanks in advance!
 
R

ruralguy via AccessMonster.com

Hmm...let's put the Bookmark code back in:

Public Function RowNum() As Variant
On Error GoTo Err_RowNum
'Purpose: Numbering the rows on a SubForm.

'Usage: SubForm Text box with ControlSource of: =RowNum()

With Me.RecordsetClone
.Bookmark = Me.Bookmark
RowNum = .AbsolutePosition + 1
End With

Exit_RowNum:
Exit Function

Err_RowNum:
If Err.Number <> 3021& Then 'Ignore "No bookmark" at new row.
Debug.Print "RowNum() error " & Err.Number & " - " & Err.Description
End If
RowNum = Null
Resume Exit_RowNum
End Function


I'm getting closer, I think, but I'm still running into a problem somewhere.
It now shows 0 in the text box if there are no records in the subform, then
when I get to the first client with records, it shows 1. Unfortunately, it
shows 1 for each of the records, not just the first one. Also, if I then
move on to the next client's records, the text box displays 0 again,
regardless of whether or not there are any records to display in the subform.
I know I'm close, I just can't quite figure it out.
Try something like this in the SubForm:
[quoted text clipped - 22 lines]
 
R

ruralguy via AccessMonster.com

Tara,
I have to apologize. I downloaded Stephan Lebans code and he has an example
with a SubForm and it *works*. Can we start this over again?
I'm getting closer, I think, but I'm still running into a problem somewhere.
It now shows 0 in the text box if there are no records in the subform, then
when I get to the first client with records, it shows 1. Unfortunately, it
shows 1 for each of the records, not just the first one. Also, if I then
move on to the next client's records, the text box displays 0 again,
regardless of whether or not there are any records to display in the subform.
I know I'm close, I just can't quite figure it out.
Try something like this in the SubForm:
[quoted text clipped - 22 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top