A procedure is calling a function to see if a table is empty through a Boolean value, however, i am receiving a compiler error. any assistance, would be appreciated.
the code is: -
If TableExists = False Then
-
DoCmd.DeleteObject acTable, "ContractImport"
-
DoCmd.DeleteObject acTable, "ContractImport$_ImportErrors"
-
End If
-
-
Public Function TableExists(strTable As String) As Boolean
-
Dim strName As String
-
-
On Error Resume Next
-
'If table exists already then strName will be > ""
-
strName = CurrentDb.TableDefs(strTable).Name
-
TableExists = Not (strName = "")
-
-
End Function
-
@jimatqsi
As previously pointed ou by jamitqsi: - If TableExists("Employees") Then
-
MsgBox "Exists"
-
Else
-
MsgBox "No exists"
-
End If
8 7064
dowlingm815,
Your function declaration - Function TableExists(strTable As String)
indicates the function requires an input parameter, yet your call to the function - If TableExists = False Then
is not supplying the needed parameter.
You need to add the name of the table to the call to the function so it knows what table name to check.
Jim
@jimatqsi
As previously pointed ou by jamitqsi: - If TableExists("Employees") Then
-
MsgBox "Exists"
-
Else
-
MsgBox "No exists"
-
End If
thanks appreciate the correction. here is the working code: -
If TableExists("ContractImport") Then
-
' delete the table if it exists
-
DoCmd.DeleteObject acTable, "ContractImport"
-
End If
-
If TableExists("ContractImport$_ImportErrors") Then
-
' delete the table if it exists
-
DoCmd.DeleteObject acTable, "ContractImport$_ImportErrors"
-
End If
-
-
-
Public Function TableExists(strTable As String) As Boolean
-
On Error GoTo Err_Hndlr
-
-
Dim strName As String
-
-
' On Error Resume Next
-
TableExists = True
-
'If table exists already then strName will be > ""
-
strName = CurrentDb.TableDefs(strTable).Name
-
TableExists = Not (strName = "")
-
Exit Function
-
-
Err_Hndlr:
-
TableExists = False
-
-
End Function
-
Given your circumstances, another option to consider is (In-Line Code): - Dim tdf As DAO.TableDef
-
Const conTABLE_NAME As String = "ContractImport"
-
-
For Each tdf In CurrentDb.TableDefs
-
If Left$(tdf.Name, Len(conTABLE_NAME)) = conTABLE_NAME Then
-
CurrentDb.TableDefs.Delete tdf.Name
-
End If
-
Next
@ADezii
I'm not sure if i follow the instructions, please keep me honest. it looks like it calculating the length of the table correct?
mary
@dowlingm815
In a Nutshell, any Table beginning with ContractImport will be DELETED!
@ADezii
that's awesome, but i still don't understand the code.
the following code, reads each table NAME in the db, correct? -
For Each tdf In CurrentDb.TableDefs
-
the next statement, calculates the length of the string, but what does the rest do? -
If Left$(tdf.Name, Len(conTABLE_NAME)) = conTABLE_NAME Then
-
i appreciate all your guidance.
mary
@dowlingm815
The code loops through every Table in the Database and if the Table Name begins with the String defined in the Constant (conTABLE_NAME ), it is then DELETED! The code is compact and efficient, but the only drawback would be if you had Tables named: - ContractImport_2
-
ContractImport_New
-
ContractImport_06182010
-
ContractImportFK
-
ContractImportYaDaYaDa
-
ContractImport Error
They would all be DELETED!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dan Bass |
last post by:
which one do you use and why?
MyString == null || MyString == ""
vs
MyString == null || MyString.Length == 0
|
by: Ron |
last post by:
Can anyone tell me how to check and see if a dataset is empty?
I am writing a search function that returns a dataset and binds it to a
datagrid. If no data is found, I would like to make the grid...
|
by: momo |
last post by:
I need to find out if a user name have been create before in a table. if so
I don't want to allow new users to recreate it.
|
by: J-P-W |
last post by:
Hi, anyone got any thoughts on this problem?
I have sales reps. that remotely send their data to an ftp server.
The office downloads all files, the code creates an empty file, then
downloads the...
|
by: lithoman |
last post by:
I'm stumped here. I run the procedure Batch_Select against the database
with @ID=18 and I get the expected data.
When it loads into a SqlDataReader, it gets messed up somehow.
Initially, after the...
|
by: rdemyan |
last post by:
Is there a way to check the validity of front-end table links on a
backend file where all permissions to data have been revoked. To get
at the data, the front end uses RWOP queries.
What I'm...
|
by: Sanjay80 |
last post by:
I want to Update one table but same time if any column from table ishaving Primary kay or Foreign Kay it should not allow me to do so. I am writting Stored Procedure
|
by: psbasha |
last post by:
Hi,
Whether we can check the empty list or dict by i"f "conditon or catch this exception by "try" and "catch" blocks.
Which will be the best practctice?.
In my work I have to play with...
|
by: BerkshireGuy |
last post by:
I have a Access database that should have data for each weekday of the
year. There is a field called DateDownloaded, which should have at
least one record for each weekday of the current year.
...
|
by: =?Utf-8?B?U2F2dm91bGlkaXMgSW9yZGFuaXM=?= |
last post by:
In a RowDataBound event, I want to check if a column is empty (it's a simple
column, not a template with a label in it). I use the following syntax to get
the value from the cell:
s =...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |