Hi guys.
i Have written code for a program with the following goal:
upon clicking the 'save button' it should check for null fields that are not supposed to be null , alert the user via message box that field is null, then set the focus on that field. after field is filled in, if the user clicks save again, it should then save the record, and call a function used to print the information just saved.
problem is: when i hit save and all is filled it, the record is being saved twice, and my label is not printing the iformation just saved.
it "prints" a blank label.
i cannot figure out what is wrong. code below:
Code:
Private Sub btnsaverecord_click()
Dim oktoclose As Boolean
Dim strid As String
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("Tbl_leadbond_yield", dbOpenDynaset)
strid = ""
oktoexit = False
oktoexit = checkbeforesaving()
If oktoexit = True Then
Call updatevalues
With rs
.AddNew
![Dicing_lots_used] = Me.TxtDicingLots
![Date_Time] = Now()
![operator] = Me.CboOperator
![Work_Order] = Me.CboWorkorder
![total_leadbonded] = Me.TxtTotalLeadbonded
![Boats] = Me.txtBoats040
![Preform_Lot] = Me.CboPreformLot040
![Pin_Lot] = Me.CboPinLot040
![Lead_Lot] = Me.CboLeadLot040
.Update
End With
rs.Close
Call PrintLabels
DoCmd.Close acForm, Me.Name
End If
End Sub
update values only does some math. i dont think that is the problem.
Code:
Private Function checkbeforesaving()
'this code checks for nullity of specific fields
If IsNull(Me.TxtDicingLots) Then
MsgBox "Please add dicing lots used."
Me.TxtDicingLots.SetFocus
checkbeforesaving = False
ElseIf IsNull(Me.CboOperator) Then
MsgBox "Please enter operator number."
Me.CboOperator.SetFocus
checkbeforesaving = False
ElseIf IsNull(Me.CboPreformLot040) Then
MsgBox "Please Enter Preform Lot information."
Me.CboPreformLot040.SetFocus
checkbeforesaving = False
ElseIf IsNull(Me.CboPinLot040) Then
MsgBox "Please enter Pin Lot number."
Me.CboPinLot040.SetFocus
checkbeforesaving = False
ElseIf IsNull(Me.CboLeadLot040) Then
MsgBox "please enter Lead Lot number."
Me.CboLeadLot040.SetFocus
checkbeforesaving = False
ElseIf IsNull(Me.txtBoats040) Then
MsgBox "Please enter number of boats built."
Me.txtBoats040.SetFocus
checkbeforesaving = False
else checkbeforesaving=true
endif
end function
Code:
Private Function PrintLabels()
Dim Show_Box As Boolean
Dim Response As Variant
Dim i As Integer
' Set the Show_Dialog variable to True.
Show_Box = True
' Begin While loop.
While Show_Box = True
' Show the input box.
Response = InputBox("Enter the number of labels to print or press Cancel to skip printing.", "Label Printing", 1)
' See if Cancel was pressed.
If Response = "" Then
' If Cancel was pressed,
' break out of the loop.
Show_Box = False
Else
' Test Entry to find out if it is numeric.
If IsNumeric(Response) = True Then
For i = 1 To Response
DoCmd.OpenReport "rpt_leadbond_yield_label", acViewPreview, , "[ID]=" & Me.ID
Next i
Show_Box = False
Else
' If the entry was wrong, show an error message.
MsgBox "Please Enter Numbers Only"
End If
End If
' End the While loop.
Wend
End Function
heeeellllppppppppppppppppppppppppppppppp