Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Columns to Existing Table

Status
Not open for further replies.

Trowser

IS-IT--Management
Dec 16, 2002
125
GB
I have a form which shows a users details for an audit
Now these users have many app's but I dont know what they are so I created a command button to add applications to the applications table.
This brings up a form with a textbox and a command button labeled Add application. When clicked I want it to add a new column to the applications table with the name of whats in the textbox. but it errors. (now I dont play with Access that much so have gotten a little stuck)
Now tried to make this fast so someone can just type in the name click add and repeat but canna get the first one to work first :)

Below is the code I have used atm

Private Sub CmdAddApp_Click()
On Error GoTo Err_CmdAddApp_Click

Dim Appname As Column
Appname = txtNewApp
Columns.Append Appname, adBoolean
txtNewApp = ""


Exit_CmdAddApp_Click:
Exit Sub

Err_CmdAddApp_Click:
MsgBox Err.Description
Resume Exit_CmdAddApp_Click

End Sub
 
thanks should have thought of that but now I get the error

You can't referance a property or method for a control unless the control has focus
 
This should do it:

Private Sub CmdAddApp_Click()
On Error GoTo Err_CmdAddApp_Click

Dim Appname As Column
txtNewApp.SetFocus
Appname = txtNewApp.Text
Columns.Append Appname.Text, adBoolean
txtNewApp.Text = ""


Exit_CmdAddApp_Click:
Exit Sub

Err_CmdAddApp_Click:
MsgBox Err.Description
Resume Exit_CmdAddApp_Click

End Sub


Hope this Helps, Let me know, either way :)

John Vogel
john@thecompuwizard.com
 
ok get errors again about objects
I think I have an idea on why

The code is running but I think that it doesn't know what table to append the columns so it errors out with a more useful error such as "right trying to append nothing as I have no idea what table you want me to append"

The problem is I have no idea how to tell it what table to append

BTW thanks for helping me John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top