PC Review


Reply
Thread Tools Rate Thread

Create new table in backend through VBA

 
 
=?Utf-8?B?TWF0dGhldyBFbGxpcw==?=
Guest
Posts: n/a
 
      6th Jul 2005
I am probably missing something simple here, but I am trying to create a new
table based on the name a user inputs in a text box on a form. That part is
fine, but I can't figure out how to create the new table in the backend (a
different .mdb where I store all of the tables). Here is the code I am using:

Private Sub Command2_Click()

Dim newTableName As Variant
Dim db As DAO.Database
Dim strSql As String

newTableName = [Text0]

' SQL string to create a new table
strSql = "SELECT *"
strSql = strSql & "INTO [" & newTableName & "] "
strSql = strSql & "FROM [tblAdjustment];"

'On Error Resume Next ' Delete table if it exists
'DoCmd.DeleteObject A_TABLE, newTableName

' Open pointer to current database"
Set db = CurrentDb()
db.Execute (strSql) ' Execute (run) the query
MsgBox "Table: [" & newTableName & "] created"
db.Close


Dim newerTableName As Variant
Dim strSqll As String

newerTableName = [Text0] & " " & "Oil"

' SQL string to create a new table

strSqll = "SELECT *"
strSqll = strSqll & "INTO [" & newerTableName & "] "
strSqll = strSqll & "FROM [tblOil];"

'On Error Resume Next ' Delete table if it exists
'DoCmd.DeleteObject A_TABLE, newerTableName

' Open pointer to current database
Set db = CurrentDb()
db.Execute (strSqll) ' Execute (run) the query
MsgBox "Table: [" & newerTableName & "] created"
db.Close
DoCmd.Close


End Sub

Thank you for the help.

Matthew Ellis
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWF0dGhldyBFbGxpcw==?=
Guest
Posts: n/a
 
      6th Jul 2005
I got it figured out. In case anyone else needs this answer, I replaced Set
db = CurrentDB() with
Set db = OpenDatabase("C:\Path to database\database.mdb")

Thanks,

Matthew Ellis

"Matthew Ellis" wrote:

> I am probably missing something simple here, but I am trying to create a new
> table based on the name a user inputs in a text box on a form. That part is
> fine, but I can't figure out how to create the new table in the backend (a
> different .mdb where I store all of the tables). Here is the code I am using:
>
> Private Sub Command2_Click()
>
> Dim newTableName As Variant
> Dim db As DAO.Database
> Dim strSql As String
>
> newTableName = [Text0]
>
> ' SQL string to create a new table
> strSql = "SELECT *"
> strSql = strSql & "INTO [" & newTableName & "] "
> strSql = strSql & "FROM [tblAdjustment];"
>
> 'On Error Resume Next ' Delete table if it exists
> 'DoCmd.DeleteObject A_TABLE, newTableName
>
> ' Open pointer to current database"
> Set db = CurrentDb()
> db.Execute (strSql) ' Execute (run) the query
> MsgBox "Table: [" & newTableName & "] created"
> db.Close
>
>
> Dim newerTableName As Variant
> Dim strSqll As String
>
> newerTableName = [Text0] & " " & "Oil"
>
> ' SQL string to create a new table
>
> strSqll = "SELECT *"
> strSqll = strSqll & "INTO [" & newerTableName & "] "
> strSqll = strSqll & "FROM [tblOil];"
>
> 'On Error Resume Next ' Delete table if it exists
> 'DoCmd.DeleteObject A_TABLE, newerTableName
>
> ' Open pointer to current database
> Set db = CurrentDb()
> db.Execute (strSqll) ' Execute (run) the query
> MsgBox "Table: [" & newerTableName & "] created"
> db.Close
> DoCmd.Close
>
>
> End Sub
>
> Thank you for the help.
>
> Matthew Ellis

 
Reply With Quote
 
Bas Cost Budde
Guest
Posts: n/a
 
      6th Jul 2005
I wonder: what place in your design do these user created tables have?

Matthew Ellis wrote:
> I am probably missing something simple here, but I am trying to create a new
> table based on the name a user inputs in a text box on a form. That part is
> fine, but I can't figure out how to create the new table in the backend (a
> different .mdb where I store all of the tables).


--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
For human replies, replace the queue with a tea

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: PictureMgr: Create Table in backend pietlinden@hotmail.com Microsoft Access VBA Modules 0 23rd Jan 2010 06:07 AM
Re: How To Duplicate Table From 1 Backend Database To Another Backend Database John W. Vinson Microsoft Access VBA Modules 0 30th Jun 2009 06:01 PM
Updateable multi-table query with inked table to a Progres backend Pete Microsoft Access Database Table Design 3 25th Mar 2009 04:44 PM
backend table not showing in linked table manager themartellekid Microsoft Access Queries 1 27th Sep 2008 12:33 AM
Copying table in Backend to another Backend =?Utf-8?B?cmRoMWE=?= Microsoft Access Form Coding 3 16th Dec 2004 05:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:11 AM.