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!

Use unbound textbox data in a query. 1

Status
Not open for further replies.

cdgeer

IS-IT--Management
Apr 8, 2008
133
US
I'm trying to use the data input by a user into an unbound textbox on a form to create an append query in VB event procedure. I can't figure out how to do that since the SQL is looking for a table or query to pull the data from?

Anyone know how to do this?
 
In the query you may use something like this:
Forms![name of mainform]![name of textbox]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
What would I put in the From clause?
 
You can't use a parameter for a table name.
A workaround is to build the SQL instruction in VBA and then execute it with either the the DoCmd.RunSQL or CurrentDb.Execute methods.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PH. Yes. Actually, that's what I'm trying to do but I can't figure out how to write the SQL. Here's what I have so far:
Private Sub cmdAppendNewTableName_Click()
Dim strTableName As String
Dim SQL1 As String

strTableName = Me.txtAddNewTable

SQL1 = "INSERT INTO [y_System/AppNameLookup]([System/AppName]) SELECT strTableName FROM ??? ;"

DoCmd.RunSQL SQL1

End Sub

Besides not knowing how to write the from clause, I also need to append the textbox data to 3 other tables besides the 1 in the Insert Into statement. I was thinking maybe a recordset of the table names would work but each table has a different name for the field that I want to append to.
 
Something like this ?
Code:
SQL1 = "INSERT INTO [y_System/AppNameLookup]([System/AppName]) VALUES ('" & strTableName & "')"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks! I'm kind of learning as I go... I never knew about the Values clause.
Works great with what I have been trying to do.
Thanks again PH!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top