Creating Tables in code

bmwilson

Registered User.
Local time
Today, 09:38
Joined
Dec 6, 2001
Messages
18
I am having trouble creating a table in access using code (vba).
The fields required are
ITEM|PRICE|UNIT|DESCRIPTION.
The name of the table will come from an inputbox value.
 
Here is your code:

'-----------------------------------
Public Sub CreateTable()

Dim strTableName As String

strTableName = InputBox("Enter new table name:", "Create New Table")

If Len(strTableName) > 0 Then
DoCmd.RunSQL "CREATE TABLE " & strTableName & " (Item TEXT (100), Price SINGLE,Unit TEXT, Description TEXT)"
End If

End Sub
'--------------------------------

Note the '(100)' that follows 'Item TEXT'. This value sets the field length. If it is omitted, the default value of 255 is used. You may also want to incorporate a check to make sure that a table with the same name doesn't already exist before creating the new one.
 
Thankyou!!!!!!!!!!!!!!!!!!

Greatly appreciated.
 

Users who are viewing this thread

Back
Top Bottom