J
Jean-Francois Gauthier
Hi,
I'm building a QBF form at the moment. The form seems to work using unbound
boxes and background coding to have strings go to the query.
I have two list boxes [dept] and [documenttype] that are the unbound on form
"QBF_form2". Dept queries values that are strings, while documenttype
queries a number. So this is where I'm thinking my problem is, but I'm not
sure.
If I enter a value in documenttype from the list box, then the strings pass
on to the query fine and I get my results. However, even though the codign
is practically the same to pass the values of both list boxes, the values
that I enter in [dept] do not seem to pass to the query, rather if I choose
for example the value "tbs" in the [dept] list box, and try to run the query,
I get a Enter Parameter Value for TBS box. In this box, if I reenter TBS,
and press ok I get my values. If I check the query after this, the
criterai for the field [dept] is showing as [tbs] rather then "TBS" as it
does for my other list box.
Here is my code.
Private Function IncludeDept() As String
On Error GoTo ProcError
'-- Create the dept Where portion of the SQL statement
Dim deptvar As Variant
Dim strTemp As String
'-- for each of the items in the ItemsSelected collection
For Each deptvar In Me!Dept.ItemsSelected()
strTemp = strTemp & "[fkDeptID]=" & Me!Dept.ItemData(deptvar) & " OR "
Next
If Len(strTemp) > 0 Then
IncludeDept = "(" & Left$(strTemp, Len(strTemp) - 4) & ")"
Else
IncludeDept = ""
End If
ExitProc:
Exit Function
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Includedept..."
Resume ExitProc
End Function
Public Function RequerySubform()
On Error GoTo ProcError
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim intRecordCount As Integer
Dim strdeptSQL As String
Dim strdocidSQL As String
Dim strCompleteSQL As String
Dim strdaterecSQL As String
Dim strWhereSQL As String
Dim strFullSQL As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("QBF_query2")
'-- If AutoRequery is set to True, or the Requery button was pressed,
'-- then re-create the Where clause for the recordsource of the subform
'**********************************************************
' Important note: You cannot use F8 to step through the following line of
code in break mode. If
' you attempt to do this, you will get run-time error # 2474:
' "The expression you entered requires the control to be in the active
window."
' You can drag the yellow pointer past this line of code.
If Me!optAutoRequery Or Screen.ActiveControl.Name = "cmdRequery" Then
'**********************************************************
'-- Store all the criteria for the Where statement
'-- into variables.
strdeptSQL = IncludeDept()
strdocidSQL = IncludeDocID()
strCompleteSQL = IncludeComplete()
strdaterecSQL = IncludeReceivedDate()
'-- Store the initial Where statement with whatever is from
'-- the dept criteria.
strWhereSQL = "Where "
If Len(strdeptSQL) <> 0 Then
If strWhereSQL <> "Where " Then
strWhereSQL = strWhereSQL & " And "
End If
strWhereSQL = strWhereSQL & strdeptSQL
End If
etc etc etc.
Any help here would be greatly appreciated.
I'm building a QBF form at the moment. The form seems to work using unbound
boxes and background coding to have strings go to the query.
I have two list boxes [dept] and [documenttype] that are the unbound on form
"QBF_form2". Dept queries values that are strings, while documenttype
queries a number. So this is where I'm thinking my problem is, but I'm not
sure.
If I enter a value in documenttype from the list box, then the strings pass
on to the query fine and I get my results. However, even though the codign
is practically the same to pass the values of both list boxes, the values
that I enter in [dept] do not seem to pass to the query, rather if I choose
for example the value "tbs" in the [dept] list box, and try to run the query,
I get a Enter Parameter Value for TBS box. In this box, if I reenter TBS,
and press ok I get my values. If I check the query after this, the
criterai for the field [dept] is showing as [tbs] rather then "TBS" as it
does for my other list box.
Here is my code.
Private Function IncludeDept() As String
On Error GoTo ProcError
'-- Create the dept Where portion of the SQL statement
Dim deptvar As Variant
Dim strTemp As String
'-- for each of the items in the ItemsSelected collection
For Each deptvar In Me!Dept.ItemsSelected()
strTemp = strTemp & "[fkDeptID]=" & Me!Dept.ItemData(deptvar) & " OR "
Next
If Len(strTemp) > 0 Then
IncludeDept = "(" & Left$(strTemp, Len(strTemp) - 4) & ")"
Else
IncludeDept = ""
End If
ExitProc:
Exit Function
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure Includedept..."
Resume ExitProc
End Function
Public Function RequerySubform()
On Error GoTo ProcError
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim intRecordCount As Integer
Dim strdeptSQL As String
Dim strdocidSQL As String
Dim strCompleteSQL As String
Dim strdaterecSQL As String
Dim strWhereSQL As String
Dim strFullSQL As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("QBF_query2")
'-- If AutoRequery is set to True, or the Requery button was pressed,
'-- then re-create the Where clause for the recordsource of the subform
'**********************************************************
' Important note: You cannot use F8 to step through the following line of
code in break mode. If
' you attempt to do this, you will get run-time error # 2474:
' "The expression you entered requires the control to be in the active
window."
' You can drag the yellow pointer past this line of code.
If Me!optAutoRequery Or Screen.ActiveControl.Name = "cmdRequery" Then
'**********************************************************
'-- Store all the criteria for the Where statement
'-- into variables.
strdeptSQL = IncludeDept()
strdocidSQL = IncludeDocID()
strCompleteSQL = IncludeComplete()
strdaterecSQL = IncludeReceivedDate()
'-- Store the initial Where statement with whatever is from
'-- the dept criteria.
strWhereSQL = "Where "
If Len(strdeptSQL) <> 0 Then
If strWhereSQL <> "Where " Then
strWhereSQL = strWhereSQL & " And "
End If
strWhereSQL = strWhereSQL & strdeptSQL
End If
etc etc etc.
Any help here would be greatly appreciated.