Conditions in Macros

  • Thread starter Thread starter Fred
  • Start date Start date
F

Fred

Is it possible to use a condition in a macro to determine
if a table exists? I'd like the macro to rename a table
IF it exists. If it doesn't, the macro should continue on
its merry way. (I do not want to use VBA for this if I
don't have to.)

Can it be done?

Thanks for any suggestions.

Fred
 
Fred,

As far as I know, it is not possible for a macro condition to test for
the existence of a database object such as a table.
 
Hi Fred,

If you are intent on using a macro then you can use DLookUp function for
your condition, example:

Condition
Action
----------------------
-------------------
DLookUp("[ID]","[the table name]") CopyObject


If the table name "[the table name]" does not exist then it will skip the
action. But of course if the table does exist and it has no data in the
field "ID" it also will be skipped. The preferred method is to use VBA
code:

Function test(tdfName As String) As Integer
On Error GoTo ErrorCheck
Dim tdf As DAO.TableDef
Set tdf = CurrentDb.TableDefs(tdfName)
Set tdf = Nothing
Exit Function
ErrorCheck:
If Err.Number = 3265 Then
test = 1
Else
test = 0
End If
Set tdf = Nothing
End Function

And then call the function from your Macro.

I hope this helps! If you have additional questions on this topic, please
respond back to this posting.


Regards,

Eric Butts
Microsoft Access Support
(e-mail address removed)
"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
<http://www.microsoft.com/security/security_bulletins/ms03-026.asp> and/or
to visit Windows Update at <http://windowsupdate.microsoft.com/> to install
the patch. Running the SCAN program from the Windows Update site will help
to insure you are current with all security patches, not just MS03-026."

This posting is provided "AS IS" with no warranties, and confers no rights



--------------------
| Content-Class: urn:content-classes:message
| From: "Fred" <[email protected]>
| Sender: "Fred" <[email protected]>
| Subject: Conditions in Macros
| Date: Wed, 22 Sep 2004 12:14:50 -0700
| Lines: 11
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| thread-index: AcSg2G7VHsqeUl/oRG+xzeKd512OLA==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.access.macros
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.access.macros:33426
| NNTP-Posting-Host: tk2msftngxa14.phx.gbl 10.40.1.166
| X-Tomcat-NG: microsoft.public.access.macros
|
| Is it possible to use a condition in a macro to determine
| if a table exists? I'd like the macro to rename a table
| IF it exists. If it doesn't, the macro should continue on
| its merry way. (I do not want to use VBA for this if I
| don't have to.)
|
| Can it be done?
|
| Thanks for any suggestions.
|
| Fred
|
 
Thanks, Eric. I'll try your suggestions.

-----Original Message-----
Hi Fred,

If you are intent on using a macro then you can use DLookUp function for
your condition, example:

Condition
Action
----------------------

-------------------
DLookUp("[ID]","[the table name]") CopyObject


If the table name "[the table name]" does not exist then it will skip the
action. But of course if the table does exist and it has no data in the
field "ID" it also will be skipped. The preferred method is to use VBA
code:

Function test(tdfName As String) As Integer
On Error GoTo ErrorCheck
Dim tdf As DAO.TableDef
Set tdf = CurrentDb.TableDefs(tdfName)
Set tdf = Nothing
Exit Function
ErrorCheck:
If Err.Number = 3265 Then
test = 1
Else
test = 0
End If
Set tdf = Nothing
End Function

And then call the function from your Macro.

I hope this helps! If you have additional questions on this topic, please
respond back to this posting.


Regards,

Eric Butts
Microsoft Access Support
(e-mail address removed)
"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
<http://www.microsoft.com/security/security_bulletins/ms03 -026.asp> and/or
to visit Windows Update at
 
Nice to know others can benefit from our questions!

Thanks, Eric. You solved my problem.

Fred.

-----Original Message-----

Thanks, Eric. I'll try your suggestions.

-----Original Message-----
Hi Fred,

If you are intent on using a macro then you can use DLookUp function for
your condition, example:

Condition
Action
----------------------

-------------------
DLookUp("[ID]","[the table name]") CopyObject


If the table name "[the table name]" does not exist then it will skip the
action. But of course if the table does exist and it
has
no data in the
field "ID" it also will be skipped. The preferred
method
is to use VBA
code:

Function test(tdfName As String) As Integer
On Error GoTo ErrorCheck
Dim tdf As DAO.TableDef
Set tdf = CurrentDb.TableDefs(tdfName)
Set tdf = Nothing
Exit Function
ErrorCheck:
If Err.Number = 3265 Then
test = 1
Else
test = 0
End If
Set tdf = Nothing
End Function

And then call the function from your Macro.

I hope this helps! If you have additional questions on this topic, please
respond back to this posting.


Regards,

Eric Butts
Microsoft Access Support
(e-mail address removed)
"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
<http://www.microsoft.com/security/security_bulletins/ms0
3
-026.asp> and/or
to visit Windows Update at
the patch. Running the SCAN program from the Windows Update site will help
to insure you are current with all security patches, not just MS03-026."

This posting is provided "AS IS" with no warranties, and confers no rights



--------------------
| Content-Class: urn:content-classes:message
| From: "Fred" <[email protected]>
| Sender: "Fred" <[email protected]>
| Subject: Conditions in Macros
| Date: Wed, 22 Sep 2004 12:14:50 -0700
| Lines: 11
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| thread-index: AcSg2G7VHsqeUl/oRG+xzeKd512OLA==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.access.macros
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.access.macros:33426
| NNTP-Posting-Host: tk2msftngxa14.phx.gbl 10.40.1.166
| X-Tomcat-NG: microsoft.public.access.macros
|
| Is it possible to use a condition in a macro to determine
| if a table exists? I'd like the macro to rename a table
| IF it exists. If it doesn't, the macro should
continue
on
| its merry way. (I do not want to use VBA for this if I
| don't have to.)
|
| Can it be done?
|
| Thanks for any suggestions.
|
| Fred
|

.
.
 
Back
Top