FrymanTCU
10-21-2008, 10:56 AM
Okay I know this is a dumb question but I have been searching the forum all morning but have not found an answer. I have a form to search the data in my database, it does this by filtering the main data table in a subform. Once the results are filtered I want to give the user the option to export the results and save the file to a location of their choice.
It seems like there are a million ways to go about this... DoCmd.OutputTo, Docmd.TransferSpreedsheet, Exporting the SQL string... I'm just not sure which way to go about tackling the problem.
Unless there is a way to select the filtered data in subform I think I will need to build a SQL query and export that. Then there is the task of saving the file to a particular location, do I open the Save As dialog box in Access or Excel?
Like I said I'm really stuck on how to tackle this one... I have pasted the code from my filter below if anyone could help I would appreciate it.
Thanks,
Rich
Private Sub Search_Click()
Const cInvalidDateError As String = "You have entered an invalid date."
Dim strWhere As String
Dim strError As String
strWhere = "1=1"
If Not IsNull(Me.cboUserName) Then
'Create Predicate
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[USER NAME] Like '*" & Me.cboUserName & "*'"
End If
If Not IsNull(Me.cboDocDescription) Then
'Add the predicate
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[DOC DESCRIPTION] Like '*" & Trim(Me.cboDocDescription) & "*'"
End If
If Nz(Me.cboAuditDecision) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[AuditID] = " & Me.cboAuditDecision & ""
End If
If Nz(Me.BranchID) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[OFFICE] Like'*" & Format(Me.BranchID, "0000") & "*'"
End If
If Nz(Me.AccountNum) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[ACCOUNT BASE] = '" & Me.AccountNum & "'"
End If
' If Opened Date From
If IsDate(Me.OpenedDateFrom) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[DOC CHANGE DATE]>= " & GetDateFilter(Me.OpenedDateFrom)
ElseIf Nz(Me.OpenedDateFrom) <> "" Then
strError = cInvalidDateError
End If
' If Opened Date To
If IsDate(Me.OpenedDateTo) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[DOC CHANGE DATE]<= " & GetDateFilter(Me.OpenedDateTo)
ElseIf Nz(Me.OpenedDateTo) <> "" Then
strError = cInvalidDateError
End If
If strError <> "" Then
MsgBox strError
Else
If Not Me.FormFooter.Visible Then
Me.FormFooter.Visible = True
DoCmd.MoveSize Height:=Me.WindowHeight + Me.FormFooter.Height
End If
Me.FollowUpSubForm.Form.Filter = strWhere
Me.FollowUpSubForm.Form.FilterOn = True
End If
End Sub
It seems like there are a million ways to go about this... DoCmd.OutputTo, Docmd.TransferSpreedsheet, Exporting the SQL string... I'm just not sure which way to go about tackling the problem.
Unless there is a way to select the filtered data in subform I think I will need to build a SQL query and export that. Then there is the task of saving the file to a particular location, do I open the Save As dialog box in Access or Excel?
Like I said I'm really stuck on how to tackle this one... I have pasted the code from my filter below if anyone could help I would appreciate it.
Thanks,
Rich
Private Sub Search_Click()
Const cInvalidDateError As String = "You have entered an invalid date."
Dim strWhere As String
Dim strError As String
strWhere = "1=1"
If Not IsNull(Me.cboUserName) Then
'Create Predicate
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[USER NAME] Like '*" & Me.cboUserName & "*'"
End If
If Not IsNull(Me.cboDocDescription) Then
'Add the predicate
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[DOC DESCRIPTION] Like '*" & Trim(Me.cboDocDescription) & "*'"
End If
If Nz(Me.cboAuditDecision) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[AuditID] = " & Me.cboAuditDecision & ""
End If
If Nz(Me.BranchID) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[OFFICE] Like'*" & Format(Me.BranchID, "0000") & "*'"
End If
If Nz(Me.AccountNum) <> "" Then
'Add it to the predicate - exact match
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[ACCOUNT BASE] = '" & Me.AccountNum & "'"
End If
' If Opened Date From
If IsDate(Me.OpenedDateFrom) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[DOC CHANGE DATE]>= " & GetDateFilter(Me.OpenedDateFrom)
ElseIf Nz(Me.OpenedDateFrom) <> "" Then
strError = cInvalidDateError
End If
' If Opened Date To
If IsDate(Me.OpenedDateTo) Then
' Add it to the predicate - exact
strWhere = strWhere & " AND " & "[AUDIT HISTORY].[DOC CHANGE DATE]<= " & GetDateFilter(Me.OpenedDateTo)
ElseIf Nz(Me.OpenedDateTo) <> "" Then
strError = cInvalidDateError
End If
If strError <> "" Then
MsgBox strError
Else
If Not Me.FormFooter.Visible Then
Me.FormFooter.Visible = True
DoCmd.MoveSize Height:=Me.WindowHeight + Me.FormFooter.Height
End If
Me.FollowUpSubForm.Form.Filter = strWhere
Me.FollowUpSubForm.Form.FilterOn = True
End If
End Sub