Help With SQL Syntax

T

Terrence

Hi All

I need help with SQL Syntax. How do I use a variable in an
SQL Statement

example

Sub test()
dim T as string
T = forms!frmTest.TxtUser

DoCmd.RunSQL "SELECT T.Field1,INTO TestTable FROM T"

End Sub

I hope somebody out there can help me.

Thanks In Advance
 
A

Allen Browne

Two issues:

1. RunSql is for action queries. Use a form (in Datasheet view if you like)
for the user interface. You can assign the RecordSource of the form, or
apply a filter.

2. Concatenate the value from the form into the SQL string, e.g.:
"SELECT ... " & T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top