R
Robert5833
Good day all;
I'm having a problem with an SQL string built in VBA. On my forms I'm using
the value in a Combo Box (e.g., cboSelChkList) as part of the SQL string to
filter the form’s recordset. The SQL created in VBA replaces the form’s
Record Source. This works fine in that scenario, but does not work in
another. The subroutine to build the SQL is as follows;
Public Sub SelectRecords()
Dim varWhereClause As Variant
Dim strAND As String
varWhereClause = Null
strAND = " AND "
If cboSelChkList & "" <> "<all>" Then
varWhereClause = (varWhereClause + strAND) & _
"tblWorkEventWork.fldChecklistHeader = """ & _
cboSelChkList & """"
End If
varWhereClause = " WHERE " + varWhereClause
Me.RecordSource = ReplaceWhereClause(Me.RecordSource, varWhereClause)
The above subroutine works in combination with two global procedures; to
build the SQL; and to replace the Record Source string of the calling object.
On the form where this procedure does work, when I watch the code in break
mode, the varWhereClause statement returns the value (built SQL string)
showing the concatenated referenced control value. In another application of
this procedure that does not work, the varWhereClause statement only returns
the source table in the SQL, but not the value of the referenced control in
the built SQL. The controls on both forms are Combo Boxes, with SQL strings
looking up a value in another table. The value in those controls are looking
up a primary key (integer), but displaying a second value (text; field name).
Where this procedure does work, I’m using the VBA produced SQL to filter the
records for that form. Where the procedure does not work is when I’m trying
to use the form's control values to filter the records for a report.
I’ve incorporated the subroutine into the report’s On Open function, but
when I run the report it doesn’t return any records (obviously because the
SQL isn’t completed). As a work around I’ve managed to filter the report with
a macro, but I prefer to use code.
I don't get any error codes or numbers; just a blank report.
Any suggestions would be greatly appreciated.
Robert
I'm having a problem with an SQL string built in VBA. On my forms I'm using
the value in a Combo Box (e.g., cboSelChkList) as part of the SQL string to
filter the form’s recordset. The SQL created in VBA replaces the form’s
Record Source. This works fine in that scenario, but does not work in
another. The subroutine to build the SQL is as follows;
Public Sub SelectRecords()
Dim varWhereClause As Variant
Dim strAND As String
varWhereClause = Null
strAND = " AND "
If cboSelChkList & "" <> "<all>" Then
varWhereClause = (varWhereClause + strAND) & _
"tblWorkEventWork.fldChecklistHeader = """ & _
cboSelChkList & """"
End If
varWhereClause = " WHERE " + varWhereClause
Me.RecordSource = ReplaceWhereClause(Me.RecordSource, varWhereClause)
The above subroutine works in combination with two global procedures; to
build the SQL; and to replace the Record Source string of the calling object.
On the form where this procedure does work, when I watch the code in break
mode, the varWhereClause statement returns the value (built SQL string)
showing the concatenated referenced control value. In another application of
this procedure that does not work, the varWhereClause statement only returns
the source table in the SQL, but not the value of the referenced control in
the built SQL. The controls on both forms are Combo Boxes, with SQL strings
looking up a value in another table. The value in those controls are looking
up a primary key (integer), but displaying a second value (text; field name).
Where this procedure does work, I’m using the VBA produced SQL to filter the
records for that form. Where the procedure does not work is when I’m trying
to use the form's control values to filter the records for a report.
I’ve incorporated the subroutine into the report’s On Open function, but
when I run the report it doesn’t return any records (obviously because the
SQL isn’t completed). As a work around I’ve managed to filter the report with
a macro, but I prefer to use code.
I don't get any error codes or numbers; just a blank report.
Any suggestions would be greatly appreciated.
Robert