why the code would delete data?

dai_lo

Registered User.
Local time
Today, 15:12
Joined
Jan 10, 2008
Messages
30
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
 
Can we see the other functions related to this one?

Form_frm_Output_Security.Set_value_Sec

and

Form_frm_Output_Admin.Set_value_Admin


.
 
Perhaps the data was deleted in one of the OnClose events of the forms you close. If was not in the code above. (Use code tags for your code samples)
 
Can we see the other functions related to this one?

Form_frm_Output_Security.Set_value_Sec

and

Form_frm_Output_Admin.Set_value_Admin


.



Public Sub Set_value_Sec(DN As String, DT As String, DD As String, Ref As String, CN As String)

Itm_Deal_Name = DN
Itm_Document_Type = DT
Itm_Document_Date = DD
Itm_reference = Ref
Itm_customer_name = CN

End Sub




Public Sub Set_value_Admin(DN As String, DT As String, DD As String, Ref As String, CN As String)

Itm_Deal_Name = DN
Itm_Document_Type = DT
Itm_Document_Date = DD
Itm_reference = Ref
Itm_customer_name = CN

End Sub
 
Perhaps the data was deleted in one of the OnClose events of the forms you close. If was not in the code above. (Use code tags for your code samples)


I removed the following Close form event. and it works fine without delete the data.

DoCmd.Close acForm, "frm_Create", acSavePrompt


any idea?

my application allows users to select a record from a list (let's call it RECORD LIST FORM) and then display the selected data in a form (UPDATE FORM) where users can update data and PRINT data in certain format.

after clicking PRINT on the UPDATE FORM, the form would print the data and automatically close as well as take user back to the RECORD LIST FORM. If i refresh the RECORD LIST FROM, I notice the PRINTED data disappeared.

please advise

Alice
 
I think it is because you are using a bound form.
I can't help you anymore without seeing the database.
For more help, i need your database or a sample describing the problem.
 

Users who are viewing this thread

Back
Top Bottom