Set up an Access database empty-handed

Source: Internet
Author: User

Software Description: Contains the source code

Description: Frmmain form a

Private Sub Command1_Click ()

On Error GoTo Err100

' Define tables and fields

The following are the referenced contents:

Dim Defdatabase as Database
Dim deftable as TableDef, Deffield as Field

Set defdatabase = Workspaces (0). OpenDatabase (App.Path & \vb-code). MDB ", 0, False)
Set deftable = defdatabase.createtabledef ("China")

' Dbbinary = 9
' Dbboolean = 1
' Dbbyte = 2
' Dbchar=18
' Dbdate=8
' Dbinteger=3
' Dblong=4
' Dbmemo=12
' Dbtext=10

' Create a Name field of 8 characters
Set Deffield = Deftable.createfield ("Name", dbtext, 8)
DefTable.Fields.Append Deffield

Set Deffield = Deftable.createfield ("Sex", dbtext, 2)
DefTable.Fields.Append Deffield

' This field is allowed to be empty
Deffield.allowzerolength = True
' Create a regular integer with an age field of 3
Set Deffield = Deftable.createfield ("Age", Dbinteger, 3)
' Field append
DefTable.Fields.Append Deffield

' Table append
DefDatabase.TableDefs.Append deftable

MsgBox "All OK, the China" table has been completed! ", vbinformation

Exit Sub

ERR100:
MsgBox "Sorry, could not establish the table. Do you want to build the Vb-code database before you build the table? ", vbcritical

End Sub

Private Sub Cmdcreate_click ()

On Error GoTo Err100

' Establish a database named Vb-code
CreateDatabase "Vb-code", dblanggeneral

MsgBox "All OK, database setup complete!" ", vbinformation

Exit Sub

ERR100:
MsgBox "Cannot build a database!" & vbCrLf & vbCrLf & Err.Description, vbinformation

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.