Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Software Development
Tag Cloud
access acer asus bios bsod computer crash desktop drive driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory missing monitor motherboard network printer problem ram random registry router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Software Development >
MS Access sql to ADD multiple COLUMN

Reply  
Thread Tools
draceplace's Avatar
Computer Specs
Senior Member with 1,202 posts.
 
Join Date: Jun 2001
Location: Conway, Arkansas
Experience: MCSE for what its worth!
02-Feb-2010, 11:45 AM #1
MS Access sql to ADD multiple COLUMN
Quck and dirty please! What is the syntax for adding multiple columns to a table.

This works:
Private Sub cmd_InCareOf_Click()
On Error GoTo Err_cmd_InCareOf_Click
sqlStr = "ALTER TABLE [Sheet in Net]" _
& "ADD COLUMN InCareOf Text(25);"

DoCmd.RunSQL sqlStr

Exit_cmd_InCareOf_Click:
Exit Sub
Err_cmd_InCareOf_Click:
MsgBox Err.Description
Resume Exit_cmd_InCareOf_Click
End Sub
______________________________________________________

This gets a Syntax in field definition #3292 Error

Private Sub cmd02_cname_Click()
On Error GoTo Err_cmd02_cname_Click
Dim stDocName As String
stDocName = "sheet_net"
MsgBox "Adding Fields to- " & stDocName, vbOKCancel


sqlStr = "ALTER TABLE " & stDocName _
& " ADD Column Cname Text(30), " _
& "ADD Column Addr1 Text(35), " _
& "ADD Column Addr2 Test(35), " _
& "ADD Column CityStZip Text(50);"
MsgBox sqlStr
DoCmd.RunSQL sqlStr

Exit_cmd02_cname_Click:
Exit Sub

Err_cmd02_cname_Click:
MsgBox Err.Description & CrLf & Err.Number
Resume Exit_cmd02_cname_Click
End Sub

Thanks for your time!
__________________
---"Wait just a minute, now. Whaddya mean, you DON'T use Regedit to send email?" - Borrowed
OBP's Avatar
OBP OBP is offline
Computer Specs
Distinguished Member with 14,665 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
02-Feb-2010, 11:53 AM #2
If you are trying to add Fields to a Table it is normal to use VBA to add them to the TableDef in the Tables Collection rather than SQL.
draceplace's Avatar
Computer Specs
Senior Member with 1,202 posts.
 
Join Date: Jun 2001
Location: Conway, Arkansas
Experience: MCSE for what its worth!
02-Feb-2010, 01:38 PM #3
I appreciate the tip OBP!!
I did it with the TableDef (like below). I'm still curious about the correct SQL syntax

If RunThis = vbOK Then
Set fld = tbl.CreateField("InCareOf", dbText, 30)
tbl.Fields.Append fld
fld.Properties("Required").Value = False
fld.Properties("AllowZeroLength").Value = True
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 03:41 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.