Solved

Creating Access File in VB6

Posted on 2000-02-17
9
181 Views
Last Modified: 2013-12-25
I would like to know how to create:
1 - Access File (.mdb)
2 - Add a Table to it (say MyTable)
3 - Add 4 Fields to "MyTable" and call them F1, F2, F3, and F4

Thank you in advance
0
Comment
Question by:khaledc
  • 7
  • 2
9 Comments
 
LVL 6

Expert Comment

by:Marine
ID: 2533596
Here is a complete DAO solution for your task. Read this article

http://support.microsoft.com/support/kb/articles/Q108/1/46.asp
0
 
LVL 6

Expert Comment

by:Marine
ID: 2533606
Here is ADO solution to create Access database from VB. It uses ADOX tools to do so. Here is a link
http://msdn.microsoft.com/library/officedev/odeopg/deovrcreatingaccessdatabase.htm
0
 
LVL 1

Author Comment

by:khaledc
ID: 2533648
I am afraid that is not enough, also I need a posted answer specified to my question.
Cheers
0
 
LVL 6

Expert Comment

by:Marine
ID: 2533674
I don't understand how you couldn't implement that sample here is the code. I tested it , it ran . with a database created.

Option Explicit

Private Sub Form_Load()
Const DB_LANG_GENERAL = ";LANGID=0x0809;CP=1252;COUNTRY=0"
      Dim db As Database
      Dim tdEmployee As New TableDef
      Dim F1 As New Field
      Dim F2 As New Field
      Dim F3 As New Field
      Dim F4 As New Field
     
      Dim indxEmployee As New Index
      Dim indxStore As New Index

      Set db = CreateDatabase("Data.MDB", DB_LANG_GENERAL)
      tdEmployee.Name = "MyTable"
      'Define your fields
      'You didn't tell what the field type was so i made some integers and some text fields
      F1.Name = "F1"
      F1.Type = 4       'Long integer

      F2.Name = "F2"
      F2.Type = 10      'Text (32)
      F2.Size = 32

      F3.Name = "F3"
      F3.Type = 10           'Text (32)
      F3.Size = 32
     
      F4.Name = "F4"
      F4.Type = 10            'Text (256)
      F4.Size = 255
       
       ' THis adds this field to the fields collection.
      tdEmployee.Fields.Append F1
      indxEmployee.Fields.Append F2
      tdEmployee.Fields.Append F3
      tdEmployee.Fields.Append F4
      'Now to make an index omit this if you don't need one.
      indxEmployee.Name = "ind_my"
      indxEmployee.Fields = "F1" ' this sets an index on field F1
      indxEmployee.Unique = True
      indxEmployee.Primary = True 'this makes a primary key on the F1 field
      'Now to append the inex to the table tdEmployee
      tdEmployee.Indexes.Append indxEmployee
      'And finally append the table to the tables collection.
      db.TableDefs.Append tdEmployee
      'Now you have a table named tdEmployee with the 4 field F1,F2,F3 & F4.
End Sub



0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Expert Comment

by:Marine
ID: 2533686
I forgot to mention please set reference to DAO library 3.6 FROM Project/References/And find there Ms Dao3.6
0
 
LVL 6

Expert Comment

by:Marine
ID: 2533697
Ok small mismatch i found there where it says
indxEmployee.Fields.Append F2
it should be tdEmployee.Fields.Append F2
Also this database will be created in Programs Folder. If you want to specify another path do this.

Set db = CreateDatabase("C:\Data.MDB", DB_LANG_GENERAL)
Put whatever path you want in between thse quotes. The datbase then will be created there. Good luck with it now. It worked i tested 2 times.
0
 
LVL 1

Author Comment

by:khaledc
ID: 2533705
I could not run the application simply because the VB compiler returning the following error while highlighting the line "Dim db as Database":
"User-Defined Type not defined"

So I assume that some references or components need to be included in my project , which one?
0
 
LVL 6

Accepted Solution

by:
Marine earned 100 total points
ID: 2533715
In my previouse comment i included that the references must be included. DAO3.6. Make sure you have it check there. Full Name of that library is
Microsoft DAO3.6 Object Library.
Please read the previouse comment on changing where i have inx where it hsould be field.
0
 
LVL 6

Expert Comment

by:Marine
ID: 2533767
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows 10 start screen issues 9 51
Determine Range to Select 5 42
MS Date Picker 64 bit 32 bit issue 12 49
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 42
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 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

12 Experts available now in Live!

Get 1:1 Help Now