VB icon

Create Access Table in VB

Email
Submitted on: 1/7/2015 1:29:00 AM
By: Anonymous (from psc cd)  
Level: Advanced
User Rating: By 6 Users
Compatibility: VB 5.0, VB 6.0
Views: 59
 
     Allows the programmer to create an MS Access table in Visual Basic where the primary key’s field data type is set to AutoNumber. It is not like creating the primary key field in Access where you can select AutoNumber date type. In VB 5 and 6 you can’t request AutoNumber for a field type in the SQL Create Table string, it does not exist. So to create a table in VB where primary key’s numeric field type will be AutoNumber, you have to do it the way the included source code shows. Hope this helps.
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :Create Access Table in VB
'**************************************
None.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Create Access Table in VB
' Description:Allows the programmer to create an MS Access table in Visual Basic where the primary key’s field data type is set to AutoNumber. It is not like creating the primary key field in Access where you can select AutoNumber date type. In VB 5 and 6 you can’t request AutoNumber for a field type in the SQL Create Table string, it does not exist. So to create a table in VB where primary key’s numeric field type will be AutoNumber, you have to do it the way the included source code shows. Hope this helps.
' By: Anonymous (from psc cd)
'
' Inputs:None.
'
' Returns:None.
'
' Assumes:None.
'
' Side Effects:None.
'**************************************

Private Sub Creat_Table()
 Dim stSQLstr As String
 Dim dbs As Database
 stSQLstr = "CREATE TABLE NameTbl (NameID COUNTER CONSTRAINT PrimaryKey PRIMARY KEY, FirstName Text (15), LastName Text (20));"
Set dbs = OpenDatabase("c:\test\Demo.mdb")
dbs.Execute stSQLstr
dbs.Close
End Sub


Other 217 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.