Important alert: (current site time 10/22/2014 9:56:48 PM EDT)
 

VB icon

Create Access Table in VB

Email
Submitted on: 6/7/2000 6:42:44 PM
By:  
Level: Advanced
User Rating: By 6 Users
Compatibility: VB 5.0, VB 6.0
Views: 16683
 
     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!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' 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: 
'
' Inputs:None.
'
' Returns:None.
'
' Assumes:None.
'
' Side Effects:None.
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=8729&lngWId=1'for details.'**************************************

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 2 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

6/7/2000 9:26:03 PMJeremy

Can you send data to an Access 2000 database using VB 6.0?
(If this comment was disrespectful, please report it.)

 
6/8/2000 7:30:32 AMDane Jones

You can send data to an access database if you have the Jet4.0 or higher driver installed. You can get it from either microsofts site or if you have Access 2000 it is already installed on your machine.
(If this comment was disrespectful, please report it.)

 
9/16/2000 10:45:32 AMJose Villalon

Hi, I've been creating a custom aplication for my university. The application is designed to help the teachers keep track of their students. The thing is i know barely nothing about databases. I know this is the way to go. So i have been reading on some database stuff.

Now for the problem, i need to know. How can i Store the Students grades?. Im wondering if creating a Table for every student is Too much. So far what i thought is creating a table like this

FLD-STUDENT-ID, FLD-SECTION, FLD-GRADE

nad link it to my other tables
so all my grades will be store there.
But i cant get the sql statements right.

Any feedback, would be apretiatted.

Thanxs
(If this comment was disrespectful, please report it.)

 
9/16/2000 10:46:53 AMs

s
(If this comment was disrespectful, please report it.)

 
10/9/2001 9:16:37 AMTom

Best
I make with you code a database.
But i will a booleaan and that type code is ...?
Can you say me where the type code stand in help (MSDN)
Thank you
(If this comment was disrespectful, please report it.)

 
1/12/2005 4:31:04 PM

To make a boolean field, try use
(If this comment was disrespectful, please report it.)

 
1/12/2005 4:32:51 PM

Try use bit in the field type.
ex: (bField bit ) creates a boolean field.
You can find more help in MSAccess help or SQL foruns.
(If this comment was disrespectful, please report it.)

 
1/12/2005 6:21:16 PMJim Ryan

this is horrible
(If this comment was disrespectful, please report it.)

 
1/21/2005 8:02:49 AMyasar mehmood

Please mention any refrences necessary for using this code.
(If this comment was disrespectful, please report it.)

 
1/21/2005 8:04:04 AMyasar mehmood

Please mention any refrence necessary for using this code.
(If this comment was disrespectful, please report it.)

 

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.