Create a table
Create a table
Create a table
Create a table
Create a table
Create a table Create a table Create a table Create a table Create a table Create a table Create a table Create a table
Create a table Create a table
Create a table
Go Back  Xtreme Visual Basic Talk > > > Create a table


Reply
 
Thread Tools Display Modes
  #1  
Old 12-17-2003, 08:31 AM
theberzerker69 theberzerker69 is offline
Centurion
 
Join Date: Dec 2003
Posts: 148
Default Create a table


Is there any way to create or copy(preferably) a table in Ms Access using Visual Basic? Many thanks!

Tommy
Reply With Quote
  #2  
Old 12-17-2003, 08:44 AM
Shurik12Create a table Shurik12 is offline
Steppe Walker

Retired Moderator
* Expert *
 
Join Date: Jul 2002
Location: Ukraine/Russia/Belgium
Posts: 7,227
Default

Hi,

You could run "CREATE TABLE..." sql.


Regards,
Shurik.
Reply With Quote
  #3  
Old 12-17-2003, 08:48 AM
msmeth's Avatar
msmeth msmeth is offline
Senior Contributor
 
Join Date: Sep 2003
Posts: 814
Default

Quote:
Originally Posted by theberzerker69
Is there any way to create or copy(preferably) a table in Ms Access using Visual Basic? Many thanks!

Tommy



Here is my code that copies 2 tables from SQL Server to Access...you can edit it as necessary. You basically have to get the structure of your original table, loop through it and append fields to the new table. Hope it helps...

Code:
tempfile = "Table1" If tempfile <> "" Then 'open the original file Set TheMP2database = OpenDatabase("MP2", dbDriverNoPrompt, False, "ODBC;DATABASE=MP2;UID=sa;PWD=;DSN=MP2") 'this will allow to get the structure of the original table Set temprecordset = TheMP2database.OpenRecordset("SELECT * FROM " & tempfile & " WHERE [ITEMNUM]='01'", dbOpenTable) 'Create a table in the MDB file named after the (original) file Set thetabledef = .CreateTableDef(tempfile(i)) 'for each field defined in the original file, 'create a field in the corresponding MDB table With temprecordset For Each FieldLoop In .Fields With FieldLoop Select Case .Type Case dbBoolean thetabledef.Fields.Append thetabledef.CreateField(.Name, dbBoolean) Case dbText thetabledef.Fields.Append thetabledef.CreateField(.Name, dbText, .Size) Case dbInteger thetabledef.Fields.Append thetabledef.CreateField(.Name, dbLong) Case dbDate 'if the field is a date field, 'converting this to a text field '(due to date conversion inconsistencies) thetabledef.Fields.Append thetabledef.CreateField(.Name, dbText, 10) Case dbSingle thetabledef.Fields.Append thetabledef.CreateField(.Name, dbSingle) Case dbDouble thetabledef.Fields.Append thetabledef.CreateField(.Name, dbDouble) Case Else thetabledef.Fields.Append thetabledef.CreateField(.Name, .Type) End Select End With Next FieldLoop End With .TableDefs.Append thetabledef temprecordset.Close TheMP2database.Close End If Next i End With TheMDBdatabase.Close
Reply With Quote
  #4  
Old 12-17-2003, 10:15 AM
theberzerker69 theberzerker69 is offline
Centurion
 
Join Date: Dec 2003
Posts: 148
Default Create Table

Here is my code to create a table within an Access Database. I found this code on another thread. The only problem is, "myConnection" and "adUseClient" have squiggly lines underneath them. Am I supposed to Dim them or something? any help would be appreciated!

myConnection = New ADODB.Connection
myConnection.CursorLocation = adUseClient
myConnection.Provider = "Microsoft.Jet.OLEDB.4.0"
myConnection.Open("C:\myPath\myDB.mdb")


myConnection.Execute("CREATE TABLE mytable" _
& "(myTextField TEXT(255)," _
& "myByteField BYTE," _
& "myDecimalField DECIMAL(3))")
Reply With Quote
  #5  
Old 12-17-2003, 11:31 AM
Squirm's Avatar
SquirmCreate a table Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

Where did you find the code?
You're obviously using VB.Net, but this code may have been written for VB6.
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Table with Field Properties Bart1123 Database and Reporting 9 10-26-2003 11:52 PM
multiple table joins simflex Database and Reporting 2 08-16-2003 05:18 PM
Create table script in Access 2000 slim steve Database and Reporting 1 08-08-2003 07:19 AM
How to create table? elahe Word, PowerPoint, Outlook, and Other Office Products 0 01-10-2003 02:36 PM
Application to get the create table statement stauf Database and Reporting 5 10-30-2002 07:08 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Create a table
Create a table
Create a table Create a table
Create a table
Create a table
Create a table Create a table Create a table Create a table Create a table Create a table Create a table
Create a table
Create a table
 
Create a table
Create a table
 
-->