module for recordset?

dette

Registered User.
Local time
Tomorrow, 01:01
Joined
Oct 7, 2004
Messages
15
i have a command button "View Records". i need a module that will check if there are records to view or if there is no record yet by using lngDemoID (autonumber). if there is no records yet, a msg will appear "There are no records to view yet.", if there is at least one record, it will display for viewing in the form. how do i do this? thanks. =)
 
On click command box

dim db as dao.recordset
dim rst as dao.recordset

set db = currentdb()
set rst = db.openrecordset("TAbleNAme")

msgbox rst.recordcount

if rst.recordcount>0 then
msgbox "no records"

else
' open form - for syntax, use the wizard in creating command button, open form
end if

end sub
 
i tried that, there's a compile error: user-defined type not defined
--> db As DAO.Recordset
 
To test this put a command button on an unbound form, name the button

cmdRecordCount

Copy the code below to the on click event of the button

Change Name of your table goes here to Your table name , make sure you put it between then " " .

When you are in the code window click Tools / References and Tick
Microsoft DAO 3.6 Object Library, if it is not already ticked.

Any problems let me know and I will post you a sample db.


Code:
Private Sub cmdRecordCount_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("Name of your table goes here")

If rst.RecordCount > 0 Then

MsgBox "There are" & " " & rst.RecordCount & " " & "records in this Database"

Else

MsgBox "There are no records in this Database"


End If

End Sub
 
dette said:
i tried that, there's a compile error: user-defined type not defined
--> db As DAO.Recordset


Sorry. Thanks John A for correcting it.
 
thanks!

it worked! thank you so much!!! :) :) :)
 
Make sure you include the second line here. It doesnt see all the records until it moves itself to the last.




Set rst = db.OpenRecordset("Name of your table goes here")

rst.movelast


If rst.RecordCount > 0 Then
 
Liv Manto,

Thank you for picking up my mistake.


Dette,

Glad that it worked for you , thanks for letting us know, that makes it worthwhile.
 
Liv Manto,

i tried to put it but a compile error occurred...
the code above worked fine... ;)
 
Liv Manto

i'm sorry, my fault. it worked (rst.movelast). thanks!
 

Users who are viewing this thread

Back
Top Bottom