Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1526
  • Last Modified:

create a new table by VBA code in another ms access database

Hi:
I am in a Database1
I need to create this table in a Database2
Table name ReportDB
Column# 1 : ReportNo  Numeric long
Column# 2 : ReportName Text 250
Column# 3 : ReportDesc Text 250
Column# 4 : RepValue Numeric long
Column# 5 : QueryName Text 250
Column# 6 : QueryDate date/time
Column# 7 : QueryRemarks memo
Column# 8 : QueryStatus Boolean

Pleas
0
Mohammad Alsolaiman
Asked:
Mohammad Alsolaiman
3 Solutions
 
Rey Obrero (Capricorn1)Commented:
try this code
Sub createTable(dbPath As String)
Dim db As DAO.Database
Set db = OpenDatabase(dbPath)
Dim sql As String
sql = "CREATE TABLE ReportDB"
sql = sql & "( "
sql = sql & "   ReportNo        LONG, "
sql = sql & "   ReportName      TEXT(250), "
sql = sql & "   ReportDesc      TEXT(250), "
sql = sql & "   RepValue        LONG, "
sql = sql & "   QueryName       TEXT(250), "
sql = sql & "   QueryDate       DATETIME, "
sql = sql & "   QueryRemarks    MEMO, "
sql = sql & "   QueryStatus     YESNO "
sql = sql & ")"
db.Execute sql
db.Close
 
End Sub

Open in new window

0
 
EXTRHMANCommented:
Here is a link to one possible solution.

http://msdn.microsoft.com/en-us/library/bb177893.aspx

0
 
Mohammad Alsolaimanapplication programmerAuthor Commented:
Hi:
Wonderful
Ok
Actually I have the same table in database1, contains data.
And I need to fill in the new table I just create it in database2 with the same data in database1.
In other word , I need to copy the table structure with the data in it from database1 to database2.
Is it possible to do so.
Pleas
0
 
dannywarehamCommented:
Of course.
You can create a table with:

Dim mySQL as String
mySQL = "INSERT INTO mynewtable FROM yourtable"
DoCmd.RunSQL mySQL
0
 
Mohammad Alsolaimanapplication programmerAuthor Commented:
pleas forgive me if i'm not fair
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now