oxicottin
Learning by pecking away....
- Local time
- Yesterday, 22:59
- Joined
- Jun 26, 2007
- Messages
- 883
I have the function below on my forms Unload Event and all I want it to do is when I close the form, if there isn't a record created then just close the form.
If frm.NewRecord Then
MsgBox "TEST 1 CLOSE FORM"
If a record was created, then it runs through qry_FindNullRecords and displays what missing info. in a popup IF there is missing data in the query BUT it still closes the form, and I don't want it to close the form if there is missing data, I want to cancel the function. What am I missing and where in the VBA below to cancel the function?
I call it from my forms unload event:
If frm.NewRecord Then
MsgBox "TEST 1 CLOSE FORM"
If a record was created, then it runs through qry_FindNullRecords and displays what missing info. in a popup IF there is missing data in the query BUT it still closes the form, and I don't want it to close the form if there is missing data, I want to cancel the function. What am I missing and where in the VBA below to cancel the function?
I call it from my forms unload event:
Code:
Private Sub Form_Unload(cancel As Integer)
cancel = fncSa(Me)
End Sub
Code:
Function fncSa(frm As Form) As Boolean
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim intX As Integer
Dim strMissnData As String
Dim strMissnProd As String
Dim lastproduct As String
Set db = CurrentDb()
Set rs = db.OpenRecordset("qry_FindNullRecords", dbOpenSnapshot)
'--------------------------------------------------------------------------------------------------
'Open the switchboard its a new record and there isnt data missing
If frm.NewRecord Then
MsgBox "TEST 1 CLOSE FORM"
'--------------------------------------------------------------------------------------------------
'Ops some data is missing, stop and show whats missing so it can be filled out, _
Run through qry_FindNullRecords and find products lengths quanity that data wasnt entered
Else
With rs
.MoveLast: .MoveFirst: intX = .RecordCount
lastproduct = .Fields("product")
strMissnData = .Fields("Product") & .Fields("strProductLength") & vbCr
Do Until .EOF
If Trim(lastproduct) <> Trim(.Fields("product")) Then
strMissnData = strMissnData & .Fields("Product") & .Fields("strProductLength") & vbCrLf
End If
lastproduct = .Fields("product")
.MoveNext
Loop
End With
MsgBox "There are " & intX & " records that are missing information for the following Products/Lengths." & vbCrLf & vbCrLf _
& strMissnData & vbCrLf _
& "You have to follow up before saving or sending!", vbExclamation, "Missing Information"
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End Function