Create a database dynamically in VB

Source: Internet
Author: User
Tags insert mdb database string

Create a database dynamically in VB
New project. Add control to write code

The following are the referenced contents:
Private Sub Command2_Click ()
Dim MyDB as DAO. Database
' Set MyDB = DAO. OpenDatabase ("D:\mydb3.mdb")
Set MyDB = DAO. OpenDatabase (App.Path + "/mydb.mdb")
Dim D as String
d = "Delete * from NewTable1"
Mydb.execute D
MsgBox "Delete all records successfully"
End Sub

Private Sub Command3_Click ()
Dim MyDB as DAO. Database
' Set MyDB = DAO. OpenDatabase ("D:\mydb3.mdb")
Set MyDB = DAO. OpenDatabase (App.Path + "/mydb.mdb")
Dim e as String
E = "Drop TABLE NewTable1"
Mydb.execute E
End Sub

Private Sub Form_Load ()
Dim MyDB as DAO. Database
' Set MyDB = DAO. Workspaces (0). CreateDatabase ("D:\mydb3.mdb", dblanggeneral)
Set MyDB = DAO. Workspaces (0). CreateDatabase (App.Path + "/mydb.mdb", dblanggeneral)
Dim Str_sql as String
Str_sql = "Create Table NewTable1 (Field1 Text (), Field2 short)"
Mydb.execute Str_sql
Dim A as String
A = "Insert into NewTable1 VALUES (' Litao ', ' 21 ')"
Mydb.execute A

Str_sql = "Create Table NewTable2 (Field1 Text (), Field2 short)"
Mydb.execute Str_sql
Mydb.close
MsgBox "successfully created Mydb3.mdb database plus a record Litao 21"
End Sub

Private Sub Command1_Click ()
Dim MyDB as DAO. Database
' Set MyDB = DAO. OpenDatabase ("D:\mydb3.mdb")
Set MyDB = DAO. OpenDatabase (App.Path + "/mydb.mdb")
Dim C as String
c = "Insert into NewTable1 VALUES (' Liqiao ', ' 20 ')"
Mydb.execute C
MsgBox "successfully insert a record Liqiao 20"
End Sub



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.