hello,
i have a function a boolean function called checkmeasurements, which checks to see if the numbers entered in three fields make sense, if one or more do not make sense, it should setfocus on the textbox in which the incorrect number is at.
i also have a function called saveandexit, which does just that.
i wrote the following code in the save button:
Code:
Private Sub btnSaveandExit_Click()
Dim blncheck As Boolean
blncheck = False
blncheck = checkmeasurements
If checkmeasurements Then
Call saveandexitfcn
End If
End Sub
when i click save btn, i want it to check the entries in those 3 text boxes, if the numbers are okay, then save, else, i want it to focus back on the box.
right now, what it does is it checks them, tells you if they are invalid entries, then saves the record anyway. might be a simple fix, but i've tried a few things and cant get it to work properly,
the two functions are below:
Code:
Private Function saveandexitfcn()
Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb()
Set rst = db.OpenRecordset("AfterEtchDieSize")
rst.AddNew
rst!Date_Time = Now()
rst!Etch_Lot = Me.cboEtchLot
rst!Measurement1 = Me.txtMeasurement1
rst!Measurement2 = Me.txtMeasurement2
rst!Measurement3 = Me.txtMeasurement3
rst!Diode_Type = Me.TxtCutType
rst!Operator = Me.txtOperator
rst!Notes = Me.txtNotes
rst!Part_Number = Me.txtPartNumber
rst!Acid_Number = Me.txtacidnumber
rst.Update
rst.Close
MsgBox ("Record saved!")
End Function
Code:
Private Function checkmeasurements()
If Me.TxtCutType = "Hex" And Me.txtcutsize = "0.125" Then 'condition
If Val(Me.txtMeasurement1) > Val(0.10825) Then 'value comparison
MsgBox ("Measurement entered is too large")
Me.txtMeasurement1.SetFocus
checkmeasurements = False
ElseIf Val(Me.txtMeasurement2) > Val(0.10825) Then
MsgBox ("Measurement entered is too large")
Me.txtMeasurement2.SetFocus
checkmeasurements = False
ElseIf Val(Me.txtMeasurement3) > Val(0.10825) Then
MsgBox ("Measurement entered is too large")
Me.txtMeasurement3.SetFocus
checkmeasurements = False
End If
ElseIf Me.TxtCutType = "Hex" And Me.txtcutsize = "0.093" Then
If Val(Me.txtMeasurement1) > Val(0.08054) Then
MsgBox ("Measurement entered is too large")
Me.txtMeasurement1.SetFocus
checkmeasurements = False
ElseIf Val(Me.txtMeasurement2) > Val(0.08054) Then
MsgBox ("Measurement entered is too large")
Me.txtMeasurement2.SetFocus
checkmeasurements = False
ElseIf Val(Me.txtMeasurement3) > Val(0.08054) Then
MsgBox ("Measurement entered is too large")
Me.txtMeasurement3.SetFocus
checkmeasurements = False
End If
ElseIf Me.TxtCutType = "Hex" And Me.txtcutsize = "0.063" Then
If Val(Me.txtMeasurement1) > Val(0.05456) Then
MsgBox ("Measurement 1 entered is too large")
Me.txtMeasurement1.SetFocus
checkmeasurements = False
ElseIf Val(Me.txtMeasurement2) > Val(0.05456) Then
MsgBox ("Measurement 2 entered is too large")
Me.txtMeasurement2.SetFocus
checkmeasurements = False
ElseIf Val(Me.txtMeasurement3) > Val(0.05456) Then
MsgBox ("Measurement 3 entered is too large")
Me.txtMeasurement3.SetFocus
checkmeasurements = False
End If
ElseIf Me.TxtCutType = "Hex" And Me.txtcutsize = "0.25" Then
If Val(Me.txtMeasurement1) > Val(0.2165) Then
MsgBox ("Measurement entered is too large")
Me.txtMeasurement1.SetFocus
checkmeasurements = False
ElseIf Val(Me.txtMeasurement2) > Val(0.2165) Then
MsgBox ("Measurement entered is too large")
Me.txtMeasurement2.SetFocus
checkmeasurements = False
ElseIf Val(Me.txtMeasurement3) > Val(0.2165) Then
MsgBox ("Measurement entered is too large")
Me.txtMeasurement3.SetFocus
checkmeasurements = False
End If
Else
checkmeasurements = True
End If