Simple-Moderate Question: Why isn't QueryDefs Property Working?

Bill Bisco

Active Member
Joined
Aug 8, 2007
Messages
446
I have a subform which is tied to a query and on this subform there is a button which when pressed is supposed to change the query on this subform.

Here is my code for the button

Code:
Private Sub cmdMoveProcessOff_Click()

Dim dbsCurrent As Database
Dim qryName As QueryDef
Dim strSQL As String

Set dbsCurrent = CurrentDb
Set qryName = dbsCurrent.QueryDefs("qryProcessSelectLSSubform")

strSQL = "SELECT tblProcesses.[Process Name], tblProcesses.ProcessSEQ, tblProcesses.StationID, tblStations.[Station Name], tblStations.Side, tblStations.StationSEQ, tblZones.[Zone Name], tblZones.ZoneSEQ, tblProcesses.Time, tblProcesses.ProcessType, tblProcesses.ProcessSubType, tblZones.LineSpeed, tblStations.StationID, tblStations.StationSide, Sum(tblElements.ElementTime) AS SumOfElementTime"
strSQL = strSQL & "FROM tblZones INNER JOIN (tblStations INNER JOIN (tblProcesses INNER JOIN tblElements ON tblProcesses.[Process ID] = tblElements.[Process ID]) ON tblStations.StationID = tblProcesses.StationID) ON tblZones.[Zone ID] = tblStations.[Zone ID]"
strSQL = strSQL & "GROUP BY tblProcesses.[Process Name], tblProcesses.ProcessSEQ, tblProcesses.StationID, tblStations.[Station Name], tblStations.Side, tblStations.StationSEQ, tblZones.[Zone Name], tblZones.ZoneSEQ, tblProcesses.Time, tblProcesses.ProcessType, tblProcesses.ProcessSubType, tblZones.LineSpeed, tblStations.StationID, tblStations.StationSide;"

'qryName.SQL = strSQL
 strSQL = qryName.SQL

End Sub
Now, when I click the button, I don't receive any error messages, and I believe the code has run, but visually I can tell that the Query has not changed. I have tried refreshing the form as well as exiting out and opening it back up. However, the Query SQL has not changed.

Does anyone have any ideas?

Sincerely,
Bill
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Two things:

1. You have the wrong line commented out. The line you want is:
Code:
qryName.SQL = strSQL

2. In building your SQL code, I see you have it broken down into three section (strSQL). Make sure when you are combining each piece, that you include a space between each, else they will run into each other and cause errors. You can put it at the end of the previous piece, or at the beginning of the current piece, i.e.
Code:
strSQL = strSQL & " FROM ...
strSQL = strSQL & " GROUP...
(note the spaces after the quote and before FROM, and after the quote and before GROUP).

To make sure everything looks good, you can do a MsgBox to return what you have built at the end of your code, i.e.
Code:
MsgBox strSQL
 
Upvote 0
Dear Joe4,

Your perceptions were spot-on. Thank you so much. Once again, You've helped me a bunch :)

Sincerely,
Bill
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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