Locopete99
Registered User.
- Local time
- Today, 09:37
- Joined
- Jul 11, 2016
- Messages
- 163
Hi Guys,
I have the following code I found online to help me create a query using check box controls so the user can add the values they require. I have slightly modded this code.
I'm having a problem because I want some default values to be added to the query to begin with.
I'm having trouble with this line as I'm not too sure on the syntax.
Basically, I want the query to have the fields Part Number, Make Or Buy, Account and Holon to be added on the front of any query as default.
Using VBA and SQL, how would I correctly select these from the table "Shikomi Forecast"
I have the following code I found online to help me create a query using check box controls so the user can add the values they require. I have slightly modded this code.
Code:
Option Compare Database
Private Sub Command0_Click()
On Error Resume Next
Dim ctl As Control
Dim strSQL As String
Dim strSQL_2 As String
Dim qdf As DAO.QueryDef
Dim qdfDemo As DAO.QueryDef
Const conQUERY_NAME As String = "S Monthly Fields" 'Physical Query Name
For Each ctl In Me.Controls 'Query every Control on the Form
If ctl.ControlType = acCheckBox Then 'Is it a Check Box?
If ctl.Value Then 'Is it selected?
strSQL = strSQL & ctl.Tag & " ," 'Build the Field Selection(s)
End If
End If
Next
If strSQL = "" Then Exit Sub 'No Fields selected, get out!
On Error GoTo Err_cmdTest_Click
'Build complete SQL Statement
strSQL_2 = "SELECT Me.Part Number, Me.Make or Buy, Me.Account, Me.Holon, " & Left$(strSQL, Len(strSQL) - 2) & " FROM Shikomi Forecast;"
'Create the QueryDef Object
Set qdfDemo = CurrentDb.CreateQueryDef(conQUERY_NAME, strSQL_2)
Exit_cmdTest_Click:
Exit Sub
Err_cmdTest_Click:
MsgBox Err.Description, vbExclamation, "Error in cmdTest_Click()"
Resume Exit_cmdTest_Click
End Sub
I'm having a problem because I want some default values to be added to the query to begin with.
I'm having trouble with this line as I'm not too sure on the syntax.
Code:
strSQL_2 = "SELECT Me.Part Number, Me.Make or Buy, Me.Account, Me.Holon, " & Left$(strSQL, Len(strSQL) - 2) & " FROM Shikomi Forecast;"
Basically, I want the query to have the fields Part Number, Make Or Buy, Account and Holon to be added on the front of any query as default.
Using VBA and SQL, how would I correctly select these from the table "Shikomi Forecast"