0

I have quite a complex requirement where I need to populate a SELECT query with parameters coming from a list box in Access. All seems to be working fine except for the SELECT part of the query, In short, I need the VBA code to populate the following in my Access query:

SELECT TRIM(ACCOUNT_NO)&","&UNITS FROM GRV_OFFICE

I have the following in my VBA code:

strSQL = "SELECT TRIM(ACCOUNT_NO)" & "," & "UNITS FROM GRV_OFFICE"

But for some reason it keeps populating it as follows in Access:

SELECT Trim(ACCOUNT_NO) AS Expr1, GRV_OFFICE.UNITS

The reason I am using trim is because this is eventually exported from the database to populate an import into another application. Without the trim there are unnecessary spaces which are messing with the subsequent import process.

So the ultimate result of this query should be the ACCOUNT_NO with a comma and then the number of units in one field.

I find this really frustrating as this should be the easy part of the project.

Any assistance will be appreciated.

1 Answer 1

1

You need to use concatenation to get two column fields together.

Below code may work:

 strSQL = "SELECT TRIM(ACCOUNT_NO) + ' ' + UNITS as newColumn FROM [GRV_OFFICE];"

Reference : https://www.mssqltips.com/sqlservertip/2985/concatenate-sql-server-columns-into-a-string-with-concat/

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that pointed me in the right direction. The final solution was: strSQL = "SELECT TRIM(ACCOUNT_NO) & ',' & UNITS as newColumn FROM [GRV_OFFICE]"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.