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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create an Access Query using VBA...?

Status
Not open for further replies.

badddger

MIS
Apr 2, 2003
3
GB
Forgive me if this is very straightforward, but I'm new to the whole area of VBA and programming.

I'd like to know how to create a query (that will appear in the 'Queries' window in Access) to concatenate four values from a table for every row in that table, using VBA behind a command button on a form. :| make sense?

I've searched the internet and have been thoroughly confused with 'QueryDef', 'RecordSet's and the like. I want to pull four fields from a table called 'newTP', then display the concatenated values in a query called 'concatnewTP'.

Can anyone help?!
 
Press the Query tab in the database window and select the table you want. Select the fields you want into the columns and the last column you type the expression to concatenated the four fields.

example: exp1:[field1]& &[field2]& &[field3]& &[field4]

Now on the toolbar you will see view icon with a down arrow, click on the down arrow and select SQL view to see the syntax.

you can copy the syntax into your vba modular

hope this helps
 
(Assuming DAO or Access 97:) If you want to create a query from VBA, you can create a querydef object:

set qdf=createQueryDef("qryNameInTheDatabaseWindow","some SQL code"

if you leave the first parameter empty, the query will not be appended to the database (temporary query).

Best regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top