help with this line of Sql please

mercmannick

Well-known Member
Joined
Jan 21, 2005
Messages
730
Hi i am running in to automation error on this line of code i am trying to run a query from Excel VBA to Access DB based on 2 dates ( so A1 = 07/12/2009 and C1 = 15/01/2010)

Code:
 sSSQL = " SELECT dbo_Roll.wo_ref AS [WO No], dbo_Roll.rhref AS Roll, dbo_Orders.customer_name AS Customer, dbo_FileNos.grade_quality_1 AS Mat, dbo_FileNos.cast_weight AS Wt, dbo_Roll.cast_date AS [Cast], dbo_FileNos.cw_drg AS CW, dbo_FileNos.cw_revision AS Rev, Max([Progs New].[MFD 2 H]) AS [MFD2 H], Max([Progs New].[MFD 2 T]) AS [MFD2 T], Max([Progs New].GEMINIS) AS GEM, Max([Progs New].[SAFOP H]) AS [SAF H], Max([Progs New].[SAFOP T]) AS [SAF T], Max([Progs New].[MFD 3]) AS MFD3, Max([Progs New].MOLLART) AS MOLL, Max([Progs New].WALDRICH) AS [WALD 1], [Progs New].COMMENTS" _
         & " FROM (dbo_Roll INNER JOIN (dbo_Orders INNER JOIN dbo_FileNos ON dbo_Orders.file_no = dbo_FileNos.file_no) ON dbo_Roll.file_no = dbo_FileNos.file_no) INNER JOIN [Progs New] ON (dbo_FileNos.cw_drg = [Progs New].CW) AND (dbo_FileNos.cw_revision = [Progs New].rev)" _
         & " WHERE (((dbo_Roll.cast_date) Between " & ShDest.Range("A1").Value & " AND " & ShDest.Range("C1").Value & "'))"

anyone help please
 
Right after you create your sSQL build statement, add the line:
Code:
MsgBox sSQL
and run it.

Compare what is returned by the Message Box with the working SQL code you have in Access. Does it match exactly?

If not, you can see where the problem areas are, and make the proper adjustments.
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Right after you create your sSQL build statement, add the line:
Code:
MsgBox sSQL
and run it.

Compare what is returned by the Message Box with the working SQL code you have in Access. Does it match exactly?

If not, you can see where the problem areas are, and make the proper adjustments.

tHANKS

NICK ALL SORTED
 
Upvote 0

Forum statistics

Threads
1,214,797
Messages
6,121,629
Members
449,041
Latest member
Postman24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top