Question SQL Statement using a variable

teric2

Registered User.
Local time
Today, 01:54
Joined
Feb 20, 2010
Messages
32
Is there a way to use a variable in an SQL statement?

Something like this:
Code:
dim mysql1, newname
 
newname = inputbox("direction on what to do go here?",,)
 
mysql1 = "INSERT INTO FinalAll SELECT newname.* FROM newname;"
DoCmd.RunSQL mysql1

Where newname would be a variable assigned from an input box.

I want to populate a single table from several different tables but have the user specify which tables to use.

Thanks in advance for any help.
 
The question implies a design issue, but this type of thing:

mysql1 = "INSERT INTO FinalAll SELECT " & newname & ".* FROM " & newname
 
Sorry? I don't follow what your saying.
 
Paul means that

"I want to populate a single table from several different tables"
shows that you have similar data in different tables which is a data normalization issue/error. Similar stuff belongs in the same container (=table), just with a tag (another field!) storing information that tells you which is which.
 
:banghead:
That's true. But I'm also using this particular Access file in a noconventional way.
Instead of pointing out the obvious, how about an answer to the question which is:

Is there a way to use a variable in an SQL statement something like my sample?
 
Instead of bitching about us not knowing what you know or do not know, how about using the solution that Paul gave you?
 
I'm sorry, but if you notice my second post I wasn't sure what Paul was saying. Then you chimed in with my tables not being setup properly.
I now realise that Paul had altered the code so I will give that a try.

Chill out.
 
Thank You pbaldy! Your code worked.
I appreciate you taking the time to answer.

And to spikepl. Sorry if there was a misunderstanding.
 

Users who are viewing this thread

Back
Top Bottom