E
eschloss
Access 2003 / WinXP
I'll preface this with the fact that I had this working (thanks to many
answered posts here) until, I believe, I started trying to get a subform's
combo box to automatically requery. That is a separate issue though.
I have a main form (frmSchedules) which has combo boxes used to create a
date range, and labels used to (when clicked) populate the subform objects
(Schedules_Subform) source object value.
I have another form (frmSchedules_Add/Edit) which is used as one of the
subforms. The code behind this form is giving me the error. There is a
combo box on this form which has querydefs attached to it.
As soon as I open the main form, I receive the Data type mismatch in
criteria expression which points to the following line of code behind the
frmSchedules_Add/Edit form:
Set rst = qdf.OpenRecordset()
When I escape out of the error popup, the subform will function as expected,
as coded so far. Any ideas why this is no longer working, or how it
initially was working?
Here is the code for most everything:
SQL behind combo box(QC_Names_Combo) on form(frmSchedules_Add/Edit):
PARAMETERS [forms]![frmSchedules]![Month_Combo1] Short,
[forms]![frmSchedules]![Day_Combo1] Short,
[forms]![frmSchedules]![Year_Combo1] Short,
[forms]![frmSchedules]![Month_Combo2] Short,
[forms]![frmSchedules]![Day_Combo2] Short,
[forms]![frmSchedules]![Year_Combo2] Short,
[forms]![frmSchedules]![Schedules_Subform]![QC_Names_Combo] Text ( 255 );
SELECT DISTINCT L_tblDate.L_Date AS [Date], Format([L_Date],"dddd") AS
[Day], L_tblArea_Tech.L_Tech AS QC, tblSchedules.Start_Work,
tblSchedules.End_Work, tblSchedules.Schedules_Reasons AS Reason,
L_tblSchedules_Reasons.L_Schedules_Reasons_Time_Entry AS Time_Entry
FROM ((tblSchedules LEFT JOIN L_tblDate ON tblSchedules.Date =
L_tblDate.L_Date_ID) LEFT JOIN L_tblArea_Tech ON tblSchedules.Name =
L_tblArea_Tech.L_Area_Tech_ID) LEFT JOIN L_tblSchedules_Reasons ON
tblSchedules.Schedules_Reasons = L_tblSchedules_Reasons.L_Schedules_Reasons_ID
WHERE (((L_tblDate.L_Date)>=[forms]![frmSchedules]![Month_Combo1] & "/" &
[forms]![frmSchedules]![Day_Combo1] & "/" &
[forms]![frmSchedules]![Year_Combo1] And
(L_tblDate.L_Date)<=[forms]![frmSchedules]![Month_Combo2] & "/" &
[forms]![frmSchedules]![Day_Combo2] & "/" &
[forms]![frmSchedules]![Year_Combo2]) AND
((L_tblArea_Tech.L_Tech)=[forms]![frmSchedules]![Schedules_Subform]![QC_Names_Combo]))
ORDER BY L_tblDate.L_Date;
VB behind form(frmSchedules): No code pertaining to subforms in Form_Load()
Private Sub Main_Label_Click()
Me!Schedules_Subform.SourceObject = "frmSchedules_Main"
End Sub
Private Sub Add_Edit_Label_Click()
Me!Schedules_Subform.SourceObject = "frmSchedules_Add/Edit"
End Sub
Private Sub Admin_Label_Click()
Me!Schedules_Subform.SourceObject = "frmSchedules_Admin"
End Sub
VB behind form(frmSchedules_Add/Edit):
Private Sub Form_Load()
Me!QC_Names_Combo.Value = Me!QC_Names_Combo.ItemData(0)
Call QC_Names_Combo_AfterUpdate
End Sub
Private Sub QC_Names_Combo_AfterUpdate()
Me.QC_Names_Combo.Requery
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim monday_count As Integer
Dim tuesday_count As Integer
Dim wednesday_count As Integer
Dim thursday_count As Integer
Dim friday_count As Integer
monday_count = 0
tuesday_count = 0
wednesday_count = 0
thursday_count = 0
friday_count = 0
Set db = CurrentDb()
Set qdf = db.QueryDefs("qrySchedules_Add/Edit")
qdf.Parameters("[Forms]![frmSchedules]![Month_Combo1]") =
[Forms]![frmSchedules]![Month_Combo1]
qdf.Parameters("[Forms]![frmSchedules]![Day_Combo1]") =
[Forms]![frmSchedules]![Day_Combo1]
qdf.Parameters("[Forms]![frmSchedules]![Year_Combo1]") =
[Forms]![frmSchedules]![Year_Combo1]
qdf.Parameters("[Forms]![frmSchedules]![Month_Combo2]") =
[Forms]![frmSchedules]![Month_Combo2]
qdf.Parameters("[Forms]![frmSchedules]![Day_Combo2]") =
[Forms]![frmSchedules]![Day_Combo2]
qdf.Parameters("[Forms]![frmSchedules]![Year_Combo2]") =
[Forms]![frmSchedules]![Year_Combo2
qdf.Parameters("[Forms]![frmSchedules]![Schedules_Subform]![QC_Names_Combo]") = [Forms]![frmSchedules]![Schedules_Subform]![QC_Names_Combo]
Set rst = qdf.OpenRecordset()
'<-----ERROR LINE
rst.MoveLast
If rst.RecordCount = 0 Then
Else
rst.MoveFirst
Do While Not rst.EOF
Select Case rst!Day
Case "Monday"
monday_count = monday_count + 1
If IsNull(rst!Reason) Or rst!Time_Entry = True Then
Me!Monday_Text1.Enabled = 1
Me!Monday_Text2.Enabled = 1
Me!Monday_Combo.Enabled = 1
Else
Me!Monday_Combo.Enabled = 1
End If
Case "Tuesday"
tuesday_count = tuesday_count + 1
If IsNull(rst!Reason) Or rst!Time_Entry = True Then
Me!Tuesday_Text1.Enabled = 1
Me!Tuesday_Text2.Enabled = 1
Me!Tuesday_Combo.Enabled = 1
Else
Me!Tuesday_Combo.Enabled = 1
End If
Case "Wednesday"
wednesday_count = wednesday_count + 1
If IsNull(rst!Reason) Or rst!Time_Entry = True Then
Me!Wednesday_Text1.Enabled = 1
Me!Wednesday_Text2.Enabled = 1
Me!Wednesday_Combo.Enabled = 1
Else
Me!Wednesday_Combo.Enabled = 1
End If
Case "Thursday"
thursday_count = thursday_count + 1
If IsNull(rst!Reason) Or rst!Time_Entry = True Then
Me!Thursday_Text1.Enabled = 1
Me!Thursday_Text2.Enabled = 1
Me!Thursday_Combo.Enabled = 1
Else
Me!Thursday_Combo.Enabled = 1
End If
Case "Friday"
friday_count = friday_count + 1
If IsNull(rst!Reason) Or rst!Time_Entry = True Then
Me!Friday_Text1.Enabled = 1
Me!Friday_Text2.Enabled = 1
Me!Friday_Combo.Enabled = 1
Else
Me!Friday_Combo.Enabled = 1
End If
Case Else
MsgBox "Recordset pulling wrong info or weekend days."
End Select
rst.MoveNext
Loop
End If
qdf.Close
rst.Close
db.Close
Set rst = Nothing
End Sub
I'll preface this with the fact that I had this working (thanks to many
answered posts here) until, I believe, I started trying to get a subform's
combo box to automatically requery. That is a separate issue though.
I have a main form (frmSchedules) which has combo boxes used to create a
date range, and labels used to (when clicked) populate the subform objects
(Schedules_Subform) source object value.
I have another form (frmSchedules_Add/Edit) which is used as one of the
subforms. The code behind this form is giving me the error. There is a
combo box on this form which has querydefs attached to it.
As soon as I open the main form, I receive the Data type mismatch in
criteria expression which points to the following line of code behind the
frmSchedules_Add/Edit form:
Set rst = qdf.OpenRecordset()
When I escape out of the error popup, the subform will function as expected,
as coded so far. Any ideas why this is no longer working, or how it
initially was working?
Here is the code for most everything:
SQL behind combo box(QC_Names_Combo) on form(frmSchedules_Add/Edit):
PARAMETERS [forms]![frmSchedules]![Month_Combo1] Short,
[forms]![frmSchedules]![Day_Combo1] Short,
[forms]![frmSchedules]![Year_Combo1] Short,
[forms]![frmSchedules]![Month_Combo2] Short,
[forms]![frmSchedules]![Day_Combo2] Short,
[forms]![frmSchedules]![Year_Combo2] Short,
[forms]![frmSchedules]![Schedules_Subform]![QC_Names_Combo] Text ( 255 );
SELECT DISTINCT L_tblDate.L_Date AS [Date], Format([L_Date],"dddd") AS
[Day], L_tblArea_Tech.L_Tech AS QC, tblSchedules.Start_Work,
tblSchedules.End_Work, tblSchedules.Schedules_Reasons AS Reason,
L_tblSchedules_Reasons.L_Schedules_Reasons_Time_Entry AS Time_Entry
FROM ((tblSchedules LEFT JOIN L_tblDate ON tblSchedules.Date =
L_tblDate.L_Date_ID) LEFT JOIN L_tblArea_Tech ON tblSchedules.Name =
L_tblArea_Tech.L_Area_Tech_ID) LEFT JOIN L_tblSchedules_Reasons ON
tblSchedules.Schedules_Reasons = L_tblSchedules_Reasons.L_Schedules_Reasons_ID
WHERE (((L_tblDate.L_Date)>=[forms]![frmSchedules]![Month_Combo1] & "/" &
[forms]![frmSchedules]![Day_Combo1] & "/" &
[forms]![frmSchedules]![Year_Combo1] And
(L_tblDate.L_Date)<=[forms]![frmSchedules]![Month_Combo2] & "/" &
[forms]![frmSchedules]![Day_Combo2] & "/" &
[forms]![frmSchedules]![Year_Combo2]) AND
((L_tblArea_Tech.L_Tech)=[forms]![frmSchedules]![Schedules_Subform]![QC_Names_Combo]))
ORDER BY L_tblDate.L_Date;
VB behind form(frmSchedules): No code pertaining to subforms in Form_Load()
Private Sub Main_Label_Click()
Me!Schedules_Subform.SourceObject = "frmSchedules_Main"
End Sub
Private Sub Add_Edit_Label_Click()
Me!Schedules_Subform.SourceObject = "frmSchedules_Add/Edit"
End Sub
Private Sub Admin_Label_Click()
Me!Schedules_Subform.SourceObject = "frmSchedules_Admin"
End Sub
VB behind form(frmSchedules_Add/Edit):
Private Sub Form_Load()
Me!QC_Names_Combo.Value = Me!QC_Names_Combo.ItemData(0)
Call QC_Names_Combo_AfterUpdate
End Sub
Private Sub QC_Names_Combo_AfterUpdate()
Me.QC_Names_Combo.Requery
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim monday_count As Integer
Dim tuesday_count As Integer
Dim wednesday_count As Integer
Dim thursday_count As Integer
Dim friday_count As Integer
monday_count = 0
tuesday_count = 0
wednesday_count = 0
thursday_count = 0
friday_count = 0
Set db = CurrentDb()
Set qdf = db.QueryDefs("qrySchedules_Add/Edit")
qdf.Parameters("[Forms]![frmSchedules]![Month_Combo1]") =
[Forms]![frmSchedules]![Month_Combo1]
qdf.Parameters("[Forms]![frmSchedules]![Day_Combo1]") =
[Forms]![frmSchedules]![Day_Combo1]
qdf.Parameters("[Forms]![frmSchedules]![Year_Combo1]") =
[Forms]![frmSchedules]![Year_Combo1]
qdf.Parameters("[Forms]![frmSchedules]![Month_Combo2]") =
[Forms]![frmSchedules]![Month_Combo2]
qdf.Parameters("[Forms]![frmSchedules]![Day_Combo2]") =
[Forms]![frmSchedules]![Day_Combo2]
qdf.Parameters("[Forms]![frmSchedules]![Year_Combo2]") =
[Forms]![frmSchedules]![Year_Combo2
qdf.Parameters("[Forms]![frmSchedules]![Schedules_Subform]![QC_Names_Combo]") = [Forms]![frmSchedules]![Schedules_Subform]![QC_Names_Combo]
Set rst = qdf.OpenRecordset()
'<-----ERROR LINE
rst.MoveLast
If rst.RecordCount = 0 Then
Else
rst.MoveFirst
Do While Not rst.EOF
Select Case rst!Day
Case "Monday"
monday_count = monday_count + 1
If IsNull(rst!Reason) Or rst!Time_Entry = True Then
Me!Monday_Text1.Enabled = 1
Me!Monday_Text2.Enabled = 1
Me!Monday_Combo.Enabled = 1
Else
Me!Monday_Combo.Enabled = 1
End If
Case "Tuesday"
tuesday_count = tuesday_count + 1
If IsNull(rst!Reason) Or rst!Time_Entry = True Then
Me!Tuesday_Text1.Enabled = 1
Me!Tuesday_Text2.Enabled = 1
Me!Tuesday_Combo.Enabled = 1
Else
Me!Tuesday_Combo.Enabled = 1
End If
Case "Wednesday"
wednesday_count = wednesday_count + 1
If IsNull(rst!Reason) Or rst!Time_Entry = True Then
Me!Wednesday_Text1.Enabled = 1
Me!Wednesday_Text2.Enabled = 1
Me!Wednesday_Combo.Enabled = 1
Else
Me!Wednesday_Combo.Enabled = 1
End If
Case "Thursday"
thursday_count = thursday_count + 1
If IsNull(rst!Reason) Or rst!Time_Entry = True Then
Me!Thursday_Text1.Enabled = 1
Me!Thursday_Text2.Enabled = 1
Me!Thursday_Combo.Enabled = 1
Else
Me!Thursday_Combo.Enabled = 1
End If
Case "Friday"
friday_count = friday_count + 1
If IsNull(rst!Reason) Or rst!Time_Entry = True Then
Me!Friday_Text1.Enabled = 1
Me!Friday_Text2.Enabled = 1
Me!Friday_Combo.Enabled = 1
Else
Me!Friday_Combo.Enabled = 1
End If
Case Else
MsgBox "Recordset pulling wrong info or weekend days."
End Select
rst.MoveNext
Loop
End If
qdf.Close
rst.Close
db.Close
Set rst = Nothing
End Sub