CHecking to see if tables are attached

N

Nigel

I am trying to get a piece of code to check and see if tables are attached, I
have a database and a welcome screen comes up, while this screen is open (it
has no links to any tables) I need it to check and see if certain table is
attached (settings), if the table is attached then I want it to ciontinue on
to the customer form, if not I want it open up another form which will allow
the user to find the data file and reattach the tables.

This is what I am using and it opens the attach form regardless. the msgbox
err statement is just there for debugging purposes to let me know what the
error number is. What is happening is that it opens the attachform regardless
and the error number is 91

Dim dbs As Database, rst As Recordset
Set rst = dbs.OpenRecordset("settings")

If err = 0 Then
DoCmd.openform "customers"
DoCmd.Close "welcome"
Else
MsgBox err
DoCmd.openform "attachtables"

DoCmd.Close "welcome"
End If

any assistance would be greatly appreciated
 
D

Dirk Goldgar

Nigel said:
I am trying to get a piece of code to check and see if tables are attached,
I
have a database and a welcome screen comes up, while this screen is open
(it
has no links to any tables) I need it to check and see if certain table is
attached (settings), if the table is attached then I want it to ciontinue
on
to the customer form, if not I want it open up another form which will
allow
the user to find the data file and reattach the tables.

This is what I am using and it opens the attach form regardless. the
msgbox
err statement is just there for debugging purposes to let me know what the
error number is. What is happening is that it opens the attachform
regardless
and the error number is 91

Dim dbs As Database, rst As Recordset
Set rst = dbs.OpenRecordset("settings")

If err = 0 Then
DoCmd.openform "customers"
DoCmd.Close "welcome"
Else
MsgBox err
DoCmd.openform "attachtables"

DoCmd.Close "welcome"
End If

any assistance would be greatly appreciated


You never set the dbs object variable to a database object. Try:

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("settings")

Also, don't forget to close rst (rst.Close) before exiting the procedure.

I assume, by the way, that somewhere in the procedure above the code you
showed, you have an On Error Resume Next statement, or else I'd expect you
to get an error message rather than being able to test the value of the Err
object.
 

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