Hi,
the following code is to call a function to display data in a form and then print it. I don't understand why the following code would delete data after printing.
please advise
Private Sub Cmd_Print_Click()
Dim db As Database
Dim lrs As DAO.Recordset
Dim LSQL As String
Dim LSQLV As String
Set db = CurrentDb()
If (cmd_Delete.Visible) Then
numTrack = Forms.frm_Record_Change_List![TrackingID]
LSQLV = "SELECT DOP_new.*, [tbl_Core Non-Core].[File Type], [tbl_Core Non-Core].[Scan] FROM [tbl_Core Non-Core] INNER JOIN DOP_new ON [tbl_Core Non-Core].[Document Type] = DOP_new.[Document Type] where [DOP_new].[TrackingID]= " & numTrack & ";"
Set lrs = db.OpenRecordset(LSQLV)
Else
LSQL = "SELECT Top 1 DOP_new.*, [tbl_Core Non-Core].[File Type], [tbl_Core Non-Core].[Scan] FROM [tbl_Core Non-Core] INNER JOIN DOP_new ON [tbl_Core Non-Core].[Document Type] = DOP_new.[Document Type] where [DOP_new].[Logged by] = '" & Itm_Logged_by & "' order by [DOP_new].[TrackingID] DESC;"
Set lrs = db.OpenRecordset(LSQL)
End If
If Not (lrs.EOF) Then
If (lrs("Shipped") = 0) Then
If (lrs("Scan") = -1) Then
If lrs("File Type") = "Security" Then
DoCmd.OpenForm "frm_Output_Security"
Call Form_frm_Output_Security.Set_value_Sec(lrs("Deal Name"), lrs("Document Type"), lrs("Document Date"), lrs("Reference #"), lrs("Client Name"))
DoCmd.PrintOut acPages
ElseIf lrs("File Type") = "Admin" Then
DoCmd.OpenForm "frm_Output_Admin"
Call Form_frm_Output_Admin.Set_value_Admin(lrs("Deal Name"), lrs("Document Type"), lrs("Document Date"), lrs("Reference #"), lrs("Client Name"))
DoCmd.PrintOut acPages
End If ' end checking File Type
Itm_TD_Number_No.SetFocus
If Not (cmd_Delete.Visible) Then
cmd_Print.Enabled = False
Else
If lrs("File Type") = "Security" Then
DoCmd.Close acForm, "frm_Output_Security", acSaveNo
Else
DoCmd.Close acForm, "frm_Output_Admin", acSaveNo
End If
DoCmd.Close acForm, "frm_Create", acSavePrompt
End If
Else
MsgBox ("Print Failure!! The latest record has SCAN = NO.")
End If 'end checking SCAN
Else
MsgBox ("Print Failure!! The latest record has been shipped")
End If 'end checking Shipped flag
Else
MsgBox ("Print Failure!! The latest record might not entered by " & Itm_Logged_by & ". Please try again.")
' lrs.MoveNext
End If 'end checking if the Recordset is empty
lrs.Close
db.Close
End Sub
the following code is to call a function to display data in a form and then print it. I don't understand why the following code would delete data after printing.
please advise
Private Sub Cmd_Print_Click()
Dim db As Database
Dim lrs As DAO.Recordset
Dim LSQL As String
Dim LSQLV As String
Set db = CurrentDb()
If (cmd_Delete.Visible) Then
numTrack = Forms.frm_Record_Change_List![TrackingID]
LSQLV = "SELECT DOP_new.*, [tbl_Core Non-Core].[File Type], [tbl_Core Non-Core].[Scan] FROM [tbl_Core Non-Core] INNER JOIN DOP_new ON [tbl_Core Non-Core].[Document Type] = DOP_new.[Document Type] where [DOP_new].[TrackingID]= " & numTrack & ";"
Set lrs = db.OpenRecordset(LSQLV)
Else
LSQL = "SELECT Top 1 DOP_new.*, [tbl_Core Non-Core].[File Type], [tbl_Core Non-Core].[Scan] FROM [tbl_Core Non-Core] INNER JOIN DOP_new ON [tbl_Core Non-Core].[Document Type] = DOP_new.[Document Type] where [DOP_new].[Logged by] = '" & Itm_Logged_by & "' order by [DOP_new].[TrackingID] DESC;"
Set lrs = db.OpenRecordset(LSQL)
End If
If Not (lrs.EOF) Then
If (lrs("Shipped") = 0) Then
If (lrs("Scan") = -1) Then
If lrs("File Type") = "Security" Then
DoCmd.OpenForm "frm_Output_Security"
Call Form_frm_Output_Security.Set_value_Sec(lrs("Deal Name"), lrs("Document Type"), lrs("Document Date"), lrs("Reference #"), lrs("Client Name"))
DoCmd.PrintOut acPages
ElseIf lrs("File Type") = "Admin" Then
DoCmd.OpenForm "frm_Output_Admin"
Call Form_frm_Output_Admin.Set_value_Admin(lrs("Deal Name"), lrs("Document Type"), lrs("Document Date"), lrs("Reference #"), lrs("Client Name"))
DoCmd.PrintOut acPages
End If ' end checking File Type
Itm_TD_Number_No.SetFocus
If Not (cmd_Delete.Visible) Then
cmd_Print.Enabled = False
Else
If lrs("File Type") = "Security" Then
DoCmd.Close acForm, "frm_Output_Security", acSaveNo
Else
DoCmd.Close acForm, "frm_Output_Admin", acSaveNo
End If
DoCmd.Close acForm, "frm_Create", acSavePrompt
End If
Else
MsgBox ("Print Failure!! The latest record has SCAN = NO.")
End If 'end checking SCAN
Else
MsgBox ("Print Failure!! The latest record has been shipped")
End If 'end checking Shipped flag
Else
MsgBox ("Print Failure!! The latest record might not entered by " & Itm_Logged_by & ". Please try again.")
' lrs.MoveNext
End If 'end checking if the Recordset is empty
lrs.Close
db.Close
End Sub