Hi,
I have a form with a subform. In the form header I have combo boxes for the user to filter data. I want to add a button that they would click to export the filtered records to a table. I have the following code and get the message that records were exported successfully but when I open the table they are not there. I don't get any errors when I compile the code but I also don't get any results in the immediate window either. Any ideas? TIA
I have a form with a subform. In the form header I have combo boxes for the user to filter data. I want to add a button that they would click to export the filtered records to a table. I have the following code and get the message that records were exported successfully but when I open the table they are not there. I don't get any errors when I compile the code but I also don't get any results in the immediate window either. Any ideas? TIA
Code:
Private Sub cmdAddToTable_Click()
'Dim tmpRS As DAO.Recordset
'Dim tmpSQL As String
Dim strWhere As String
Dim strSQL As String
Dim tmpRS As DAO.Recordset
Dim lngRecord_Count As Long
Set tmpRS = Me!frmPacsVerificationSubForm.Form.RecordsetClone
'We do the following to get an accurate count of records.
With tmpRS
.MoveLast
.MoveFirst
End With
lngRecord_Count = tmpRS.RecordCount
If lngRecord_Count = 0 Then
MsgBox "No records to export."
GoTo Exit_Now
End If
tmpRS.Close
Set tmpRS = Nothing
If Me!frmPacsVerificationSubForm.Form.FilterOn = True Then 'filter had been applied.
strWhere = Me!frmPacsVerificationSubForm.Form.Filter
If strWhere <> "" Then
strWhere = "WHERE " & strWhere
End If
End If
strSQL = "INSERT INTO tblResultsTrackingFreeForm (" & _
"[ID], " & _
"[Request ID], " & _
"[Product Rating], " & _
"[Pay Type], " & _
"[Amount], " & _
"[Create Date], " & _
"[Approved Date], " & _
"[Approver ADENT], " & _
"[Business_Line], " & _
"[QAComments1], " & _
"[QAComments2], " & _
"[QAComments3], " & _
"[SPA]) "
strSQL = strSQL & "SELECT tblPacsfreeform.ID, " & _
"tblPacsfreeform.[Request ID], " & _
"tblPacsfreeform.RISK_WEIGHT_RATING_DESC, " & _
"tblPacsfreeform.[Payment Type Description], " & _
"tblPacsfreeform.[Transaction Amount], " & _
"tblPacsfreeform.[Created Date], " & _
"tblPacsfreeform.[Approved Date], " & _
"tblPacsfreeform.[Approved By Full Name], " & _
"tblPacsfreeform.LOB, " & _
"tblPacsfreeform.[Memo(Most Recent)], " & _
"tblPacsfreeform.[Memo(2nd Most Recent)], " & _
"tblPacsfreeform.[Memo(3rd Most Recent)], " & _
"tblPacsfreeform.[AddToSPA] " & _
"FROM tblPACSTemplate " & _
strWhere & ";"
With DoCmd
.SetWarnings False
.RunSQL strSQL
.SetWarnings True
End With
MsgBox lngRecord_Count & " records were added to results tracking table", vbOKOnly, "Records added successfully"
Exit_Now:
Exit Sub
End Sub