marlind
asked on
What is the command to check for a table and then give the user a message if it is not.
I would like my database to check for table crexport and if it is not there I need it to display instructions (msgbox) for the user to follow. If it is there I will have it "do something". Thanks for any help.
You need a function for this - this will do it:
Function ExistsTable(strTableName As String) As String
ExistsTable=Not IsNull(DLookup("[Name]","M SysObjects ","[Name]= '" & strTableName & "' AND Type=6"))
End Function
You can now do:
If ExistsTable("MyTable")=Fal se Then
MsgBox "Do something!"
End If
Function ExistsTable(strTableName As String) As String
ExistsTable=Not IsNull(DLookup("[Name]","M
End Function
You can now do:
If ExistsTable("MyTable")=Fal
MsgBox "Do something!"
End If
This line:
Function ExistsTable(strTableName As String) As String
should obviously read:
Function ExistsTable(strTableName As String) As Boolean
:-)
Function ExistsTable(strTableName As String) As String
should obviously read:
Function ExistsTable(strTableName As String) As Boolean
:-)
ASKER
shanesuebsahakarn,
I have this
Function ExistsTable(strTableName As String) As Boolean
ExistsTable = Not IsNull(DLookup("[Name]", "MSysObjects", "[Name]='" & strTableName & "' AND Type=6"))
End Function
I have this on a command button
If ExistsTable("CRExport") = False Then
MsgBox "Do something!", vbCritical, "Quality Control"
The message box appears even if the table is there. I would like a frmuserselection to open if the table is there, and the msgbox to appear if the table is not there. I played around with the if statement put couldn't get my form to come up. I must be missing something.
I have this
Function ExistsTable(strTableName As String) As Boolean
ExistsTable = Not IsNull(DLookup("[Name]", "MSysObjects", "[Name]='" & strTableName & "' AND Type=6"))
End Function
I have this on a command button
If ExistsTable("CRExport") = False Then
MsgBox "Do something!", vbCritical, "Quality Control"
The message box appears even if the table is there. I would like a frmuserselection to open if the table is there, and the msgbox to appear if the table is not there. I played around with the if statement put couldn't get my form to come up. I must be missing something.
On Shane's answer,
I think type for tables is = 1, then:
Function ExistsTable(strTableName As String) As Boolean
ExistsTable=Not IsNull(DLookup("[Name]","M SysObjects ","[Name]= '" & strTableName & "' AND Type=1"))
End Function
I think type for tables is = 1, then:
Function ExistsTable(strTableName As String) As Boolean
ExistsTable=Not IsNull(DLookup("[Name]","M
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Nestorio beat me to it :)
ASKER
shanesuebsahakarn,
Perfect. Now I have to figure out what my do something instructions should be. Thanks for the help.
Perfect. Now I have to figure out what my do something instructions should be. Thanks for the help.
marlind
did you try my post?
If TableExists("CRExport")=Fa lse Then
MsgBox "Do something"
else
Docmd.OpenForm "frmuserselection"
end if
did you try my post?
If TableExists("CRExport")=Fa
MsgBox "Do something"
else
Docmd.OpenForm "frmuserselection"
end if
ASKER
It may work too but I chose shanesuebsahakarn answer first. Thank you for giving the replying to my question.
marlind
It will work definitely, and sad to say that i posted first and never got any chance.
It will work definitely, and sad to say that i posted first and never got any chance.
Function TableExists(TableName as string) as boolean
dim db as database, tbl as tabledef
set db as currentdb()
tableexists=false
For Each tbl In db.TableDefs
If tbl.Name = TableName Then
tableExists = True
Exit Function
End If
Next tbl
End Function