Using advice from the very helpful people on this forum and some other sources I have managed to get this far with my form to report adventures. I have written this bit of VB code which SHOULD run when I hit the button that says generate report. The report should generate based on the answers to drop down boxes in the form. It works fine if the form is blank. However as soon as I try to limit it I get a "Data type mismatch in criteria expression" on the last line before the End If End Sub lines. Anything with frm in it is the dropdown value from the form. I THINK the problem is the WhereCondition:=Mid(strWhere, 6) but I dont know how to fix it. Any suggestions? THANKS! Zelda 
Guess I should add there are 6 tables - the one I am trying to generate the report from basically calls on all the other tables to get filled out. So I have Investigator, Site, Length, Discipline, StudentParticipation, and Project. The only two unique columns in project (besides its identifier) are Project_Name and Project_Description. The Investigators Column in project is based on a join query to join first and last name from the Investigator table.
Private Sub CmdRunReport_Click()
Dim strWhere As String 'String variable to store where clause
If Len(Me.Frmsite & "") > 0 Then
strWhere = strWhere & " And Project.location = '" & Me.Frmsite & "'"
End If
If Len(Me.StPFrm & "") > 0 Then
strWhere = strWhere & " And project.Student_Participation = '" & Me.StPFrm & "'"
End If
If Len(Me.FrmName & "") > 0 Then
strWhere = strWhere & " And project.Investigators = '" & Me.FrmName & "'"
End If
If Len(Me.FrmDiscp & "") > 0 Then
strWhere = strWhere & " And project.Discipline = '" & Me.FrmDiscp & "'"
End If
If Len(Me.FrmLength & "") > 0 Then
strWhere = strWhere & " And Project.length = '" & Me.FrmLength & "'"
End If
'If Me.chkFinal = True Then
' strWhere = strWhere & " AND startedFrm=true"
' End If
If Len(strWhere & "") = 0 Then
' no options selected. Open report with no where condition
DoCmd.OpenReport "ReportProject", acViewPreview
Else
' remove first "AND" from where condition and pass across to report
DoCmd.OpenReport "ReportProject", acViewPreview, WhereCondition:=Mid(strWhere, 6)
End If
End Sub
Guess I should add there are 6 tables - the one I am trying to generate the report from basically calls on all the other tables to get filled out. So I have Investigator, Site, Length, Discipline, StudentParticipation, and Project. The only two unique columns in project (besides its identifier) are Project_Name and Project_Description. The Investigators Column in project is based on a join query to join first and last name from the Investigator table.
Private Sub CmdRunReport_Click()
Dim strWhere As String 'String variable to store where clause
If Len(Me.Frmsite & "") > 0 Then
strWhere = strWhere & " And Project.location = '" & Me.Frmsite & "'"
End If
If Len(Me.StPFrm & "") > 0 Then
strWhere = strWhere & " And project.Student_Participation = '" & Me.StPFrm & "'"
End If
If Len(Me.FrmName & "") > 0 Then
strWhere = strWhere & " And project.Investigators = '" & Me.FrmName & "'"
End If
If Len(Me.FrmDiscp & "") > 0 Then
strWhere = strWhere & " And project.Discipline = '" & Me.FrmDiscp & "'"
End If
If Len(Me.FrmLength & "") > 0 Then
strWhere = strWhere & " And Project.length = '" & Me.FrmLength & "'"
End If
'If Me.chkFinal = True Then
' strWhere = strWhere & " AND startedFrm=true"
' End If
If Len(strWhere & "") = 0 Then
' no options selected. Open report with no where condition
DoCmd.OpenReport "ReportProject", acViewPreview
Else
' remove first "AND" from where condition and pass across to report
DoCmd.OpenReport "ReportProject", acViewPreview, WhereCondition:=Mid(strWhere, 6)
End If
End Sub
Last edited: