DCount

Sezzy

Registered User.
Local time
Today, 17:27
Joined
Nov 3, 2004
Messages
19
I am trying to get the record count from a table. I want the table name to come from the filename that the user inputs into the form. The code I am using at the moment is:

tblname = Me.filename

totrec = DCount("*", tblname)

Me.TotalRec = totrec

But it throws an error, saying I entered an invalid argument.
I've seen it written like this on another database so not sure why it isn't working!
If I manually put the table name into it like so:
totrec = DCount("*", "TEST")
Then it works fine. I just need to how to put the tablename from the form into it.

Thanks alot
 
Opening a table

I am now having trouble trying to open a table aswell:

tblname = Me.filename

DoCmd.OpenTable tblname

Not sure what I'm doing wrong!!!!
 
Sezzy,

First, what was Me.filename equal to? If it really equates to one of your
tables, then you must put:

totrec = DCount("*", "[" & tblname & "]")

As to Opening a table, what do you want to do with the data? Are you
going to modify it? You generally need a recordset to work with data
like that. With a little more info, I'll give you an example.

Wayne
 
WayneRyan,

I opened the database today, and it worked!! I really don't understand it!!

Thanks for your help. Oh and when I open the table it's only to check that data looks ok in the table.

Cheers :)
 

Users who are viewing this thread

Back
Top Bottom