Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Record Numbers

Status
Not open for further replies.

applemacman

Technical User
Mar 26, 2008
9
0
0
GB
Hi People!

Heres the problem, i have created a search page with different criteria, this then runs a query which will return a number of results depending on the users selections.
When there is more than one record returned, the user uses buttons to view the different records. I would like to be able to make these buttons dissapear if there is only one record.
It would also be useful to tell the user how many records have been returned, is this possible?

Thanks
 
Hi

A recordset has a .recordcount property, which as its name suggests returns the number of records in the recordset. Be warning howver, the .recordcount is not accurtaley populated until the last record has been accessed, so it is usually necessary to execute a .movelast .movefirst before using the .recordcount property.

It is not clear to me from your post just how you are displaying the results, if it is via abound form, you can get at the .recordcount, .movefirst, .movelast via the .recordsetclone of the form.

If you are using a query to create recordset in code, you can reference then via the recordset object.


Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
 
thanks for the reply,

where is this recordsetclone on the form? what would i have to type in? I thought that i would have to put something in VB to check the number and then if greater than 1 make the buttons.visible??

sorry i know you have answered my question however i just dont understand (only just started using access!)

thanks again
 
Hi

OK, no problem

In the oncurrent event of the form

If me.recordsetclone.recordcount > 0 then
me.recordsetclone.movelast
me.recordsetclone.movefirst
if me.recordsetclone > 1 then
' code here to make visible whatever
else
' code here to hide it
end if
else
' code here to hide it or say no results whatever
end if



Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
 
Hi thanks for that, i copied it all in and when i open the form it produces a run time error '3001' "invalid argument" and then have to debug in VB. It hilights this line of the code in yellow, If Me.RecordsetClone > 1 Then

Private Sub Form_Current()
'count number of records'
If Me.RecordsetClone.RecordCount > 0 Then
Me.RecordsetClone.MoveLast
Me.RecordsetClone.MoveFirst
If Me.RecordsetClone > 1 Then
'make visible'
Command31.Visible = True
Command30.Visible = True
Label33.Visible = True
Box32.Visible = True
Else
'hide them'
Command31.Visible = False
Command30.Visible = False
Label33.Visible = False
Box32.Visible = False
End If
Else
'say no results due to parameters'
MsgBox "The Criteria you have choosen have returned no results." _
& vbCrLf & "Please try again, excluding some parameters.", vbExclamation, _
"Too many parameters"
End If



Any Ideas?
 
sorry, my typing, should be

If Me.RecordsetClone.recordcount > 1 Then

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
 
thanks a lot for the help! solved the problem perfectly!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top