Solved

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

Posted on 2008-10-10
5
820 Views
Last Modified: 2013-11-27
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
Comment
Question by:Mohammad Alsolaiman
5 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 250 total points
Comment Utility
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
 
LVL 1

Assisted Solution

by:EXTRHMAN
EXTRHMAN earned 100 total points
Comment Utility
Here is a link to one possible solution.

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

0
 

Author Comment

by:Mohammad Alsolaiman
Comment Utility
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
 
LVL 26

Assisted Solution

by:dannywareham
dannywareham earned 150 total points
Comment Utility
Of course.
You can create a table with:

Dim mySQL as String
mySQL = "INSERT INTO mynewtable FROM yourtable"
DoCmd.RunSQL mySQL
0
 

Author Closing Comment

by:Mohammad Alsolaiman
Comment Utility
pleas forgive me if i'm not fair
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now