UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Add A Character To Start Of Table Names, Access 2016    
 
   
johnpdmccall
post Mar 14 2018, 11:22 AM
Post#1



Posts: 1,727
Joined: 14-March 00
From: Scotland


Hi Folks

Can anyone show me an example of how to use db.TblDefs to add a character to the beginning of all table names in a .accdb ?


--------------------
Cheers,
John
Go to the top of the page
 
doctor9
post Mar 14 2018, 12:22 PM
Post#2


UtterAccess Editor
Posts: 18,324
Joined: 29-March 05
From: Wisconsin


John,

Step 1. MAKE A BACKUP.
Step 2.

CODE
    Dim objTableDef As TableDef
    
    For Each objTableDef In CurrentDb.TableDefs
        objTableDef.name = "X" & objTableDef.name
    Next


Hope this helps,

Dennis

--------------------
(;,;) Li'l Cthulu says: Please talk about what you're trying to do, as well as how you're doing it.
Changing your real table name to "Table1" and your real form name to "Form1" in your posts makes it more difficult to understand what's going on, not easier.
Guidelines for Posting Questions
Go to the top of the page
 
johnpdmccall
post Mar 14 2018, 12:49 PM
Post#3



Posts: 1,727
Joined: 14-March 00
From: Scotland


Thanks Dennis,

I like your approach to writing instructions:

"Step 1. MAKE A BACKUP." ohyeah.gif


--------------------
Cheers,
John
Go to the top of the page
 
johnpdmccall
post Mar 14 2018, 01:08 PM
Post#4



Posts: 1,727
Joined: 14-March 00
From: Scotland


That works nicely but stops when it finds a system table.
How do I get it to skip anything beginning with "MSys"


--------------------
Cheers,
John
Go to the top of the page
 
doctor9
post Mar 14 2018, 01:16 PM
Post#5


UtterAccess Editor
Posts: 18,324
Joined: 29-March 05
From: Wisconsin


John,

Sorry, I was just providing the basic syntax for renaming a table in my first reply. You can wrap that code inside an IF test. Something like:

CODE
If Left(objTableDef.name,4) <> "MSys" Then
'   The renaming bit
End If


Hope this helps,

Dennis

--------------------
(;,;) Li'l Cthulu says: Please talk about what you're trying to do, as well as how you're doing it.
Changing your real table name to "Table1" and your real form name to "Form1" in your posts makes it more difficult to understand what's going on, not easier.
Guidelines for Posting Questions
Go to the top of the page
 
johnpdmccall
post Mar 14 2018, 01:28 PM
Post#6



Posts: 1,727
Joined: 14-March 00
From: Scotland


No Worries Dennis I was trying to work it out and I was getting there with the Left() bit but didn't know to use <> to excludes the MSys tables.

For anyone else who needs this it now looks like this:

CODE
For Each objTableDef In CurrentDb.TableDefs
If Left(objTableDef.Name, 4) <> "MSys" Then
        objTableDef.Name = "X" & objTableDef.Name
    End If
    Next


Works for me!


--------------------
Cheers,
John
Go to the top of the page
 
LPurvis
post Mar 14 2018, 02:09 PM
Post#7


UtterAccess Editor
Posts: 16,271
Joined: 27-June 06
From: England (North East / South Yorks)


Dennis, your new do keeps making me think it's Glenn replying. :-)
I really should look at usernames more, but that's soooo time consuming. :-p

--------------------
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    20th June 2018 - 09:48 PM