2 Replies - 13574 Views - Last Post: 12 August 2008 - 12:40 AM Rate Topic: -----

#1 arnoldkit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-August 08

creating a table using Microsoft Access in Visual Basic 6.0?

Posted 11 August 2008 - 01:26 AM

creating a table using Microsoft Access in Visual Basic 6.0? can you help me on this...
Is This A Good Question/Topic? 0
  • +

Replies To: creating a table using Microsoft Access in Visual Basic 6.0?

#2 dineeshd  Icon User is offline

  • member icon

Reputation: 38
  • View blog
  • Posts: 619
  • Joined: 30-June 08

Re: creating a table using Microsoft Access in Visual Basic 6.0?

Posted 11 August 2008 - 04:35 AM

Code to create a table in MS Acess :

Private Sub Form_Load()
Const strCon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db1.mdb;Persist Security Info=False"

Dim Con As New ADODB.connection
Dim Cmd As New ADODB.Command

Con.ConnectionString = strCon
Con.Open

Cmd.ActiveConnection = Con
Cmd.CommandText = "create table Table_Name (Col1 number, Col2 Varchar(15))"

Cmd.Execute
Con.Close

End Sub 


Hope This helps..... :rolleyes:
Was This Post Helpful? 0
  • +
  • -

#3 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: creating a table using Microsoft Access in Visual Basic 6.0?

Posted 12 August 2008 - 12:40 AM

you can also use the DAo object to create a table in access
Note ; if you use access 2000 or greater then use
The reference DAO3.6
using the table def you can create a table and view all the tables in a database
and querydef you can create a query and create a new query
Dim db As Database
Dim rs As Recordset
Dim tbfs As TableDefs
Dim qrfs As QueryDefs
Dim tbf As TableDef
Dim qrf As QueryDef

Private Sub Command1_Click()
Dim fld As Field
'Note When you create a table  verify that tablename already exists and same thing also for fields
 Set tbf = db.CreateTableDef("NEWTABLE", , "NEWTABLE")
	With tbf
		Set fld = .CreateField("Field1", dbText, 10)
		fld.DefaultValue = "Sample"
		.Fields.Append fld
		Set fld = .CreateField("Field2", dbLong)
		fld.DefaultValue = 0
		.Fields.Append fld
	End With
	MsgBox tbf.Fields.Count
tbfs.Append tbf

End Sub

Private Sub Form_Load()

Set db = OpenDatabase("F:\newproject\NEWTabledefProject\Database\Database.mdb") 'App.Path & "\Database\Database.meb")
Set tbfs = db.TableDefs
Set qrhs = db.QueryDefs
For i = 0 To db.TableDefs.Count - 1
	Set tbf = db.TableDefs(i)
	If Not UCase(tbf.Name) Like "*SYS*" Then
		List1.AddItem tbf.Name
	End If
Next
End Sub


hope you get it differently and moreover it os used for only access

This post has been edited by thava: 13 August 2008 - 05:58 PM

Was This Post Helpful? 1

Page 1 of 1