convert query to sql issue?

siamandm
BronzeLounger
Posts: 1234
Joined: 01 May 2016, 09:58

convert query to sql issue?

Post by siamandm »

Hi
i have a query created with designed view, i changed the view to SQL view and used in VBA code i get this error
Capture.PNG
why is this happens please?
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78519
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: convert query to sql issue?

Post by HansV »

You cannot refer to controls on forms when you use DAO. You can get around this by concatenating the value of the combo box into the SQL string: change

... tblSection_District_List.LocationID_FK = [Forms]![frmSummary]![cboLocation]) ...

to

... tblSection_District_List.LocationID_FK = " & [Forms]![frmSummary]![cboLocation] & ") ...

If you call this code from frmSummary, you can even use

... tblSection_District_List.LocationID_FK = " & Me![cboLocation] & ") ...
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1234
Joined: 01 May 2016, 09:58

Re: convert query to sql issue?

Post by siamandm »

thanks a lot working now:)