By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

Counting Columns in a table using code

P: n/a
As any good code pirate would, I have duly copied the code suggested in
this forum from 1998(VBA method to determine number of columns in a
table??) but I keep getting an error "Object Required"...

ColumnNum = db.TableDefs(QTable1).Fields.Count

http://groups.google.ca/group/comp.d...1aa8a5d4841b0).

While I am very happy to change with the times, I would like it if I
could get the rather simple code to work... I have a feeling the answer
is going to be rather simple.

Cheers

Reg

Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Br
Regnab <p.*******@gmail.com> wrote:
As any good code pirate would, I have duly copied the code suggested
in this forum from 1998(VBA method to determine number of columns in a
table??) but I keep getting an error "Object Required"...

ColumnNum = db.TableDefs(QTable1).Fields.Count

http://groups.google.ca/group/comp.d...1aa8a5d4841b0).

While I am very happy to change with the times, I would like it if I
could get the rather simple code to work... I have a feeling the
answer is going to be rather simple.

Cheers

Reg


Umm, did you set the value of db??

eg.
Dim db as Database
Set db = CurrentDB()

--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #2

P: n/a
Yep - that'd be the problem. Like I said - a bit of a beginner. Cheers
Brad. Problem now is I'm getting a "User-defined type not defined"
error on the 'Dim db as Database' which I think is related to my
references, but not sure. Another basic solution I'm guessing... ideas?

Nov 13 '05 #3

P: n/a
you need to register the DAO library. ADO is the default for all
versions after 97.

Open a code window, Tools, References, and then click the DAO 3.x
reference.

Nov 13 '05 #4

P: n/a
Br
pi********@hotmail.com wrote:
you need to register the DAO library. ADO is the default for all
versions after 97.

Open a code window, Tools, References, and then click the DAO 3.x
reference.


And if you have ADO and DAO registered you need to prefix which in your
declaration... good practice to do it at all times I reckon.

eg.

DIM myDB as DAO.Database

or

DIM myDB as ADODB.Database
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.