Hi All,
Currently, no field can be empty, when I hit save. My question is, how can I make it so that when Primed is selected and any other fields are empty it would auto writes N/A on the database when I click save?
Function ValidateEntries() As Boolean
ValidateEntries = True
Dim iMaterialID As Variant
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Print")
iMaterialID = frmForm.txtMaterialID.Value
With frmForm
'Default Color
.txtMaterialID.BackColor = vbWhite
.cmbValve.BackColor = vbWhite
.txtintfineflow.BackColor = vbWhite
.txtintcoarseflow.BackColor = vbWhite
.txtFineFlow.BackColor = vbWhite
.txtCoarseFLow.BackColor = vbWhite
.txtComments.BackColor = vbWhite
'--------------------------------
If Trim(.txtMaterialID.Value) = "" Then
MsgBox "Please enter Material ID.", vbOKOnly + vbInformation, "Material ID"
ValidateEntries = False
.txtMaterialID.BackColor = vbRed
.txtMaterialID.SetFocus
Exit Function
End If
'Validating Duplicate Entries
If Not sh.Range("B:B").Find(what:=iMaterialID, lookat:=xlWhole) Is Nothing Then
MsgBox "Duplicate Material ID found.", vbOKOnly + vbInformation, "Material ID"
ValidateEntries = False
.txtMaterialID.BackColor = vbRed
.txtMaterialID.SetFocus
Exit Function
End If
If Trim(.txtComments.Value) = "" Then
MsgBox "Please enter Comments.", vbOKOnly + vbInformation, "Comments"
ValidateEntries = False
.txtComments.BackColor = vbRed
.txtComments.SetFocus
Exit Function
End If
'Validating Scale
If .optLarge.Value = False And .optSmall.Value = False And .optBoth.Value = False Then
MsgBox "Please select Scale.", vbOKOnly + vbInformation, "Scale"
ValidateEntries = False
Exit Function
End If
If .CheckYes.Value = False And .CheckNo.Value = False Then
MsgBox "Please select Locked Yes or No.", vbOKOnly + vbInformation, "Locked"
ValidateEntries = False
Exit Function
End If
If .CheckYess.Value = False And .CheckNoo.Value = False Then
MsgBox "Please select Locked Yes or No.", vbOKOnly + vbInformation, "Locked"
ValidateEntries = False
Exit Function
End If
If Trim(.cmbValve.Value) = "" Then
MsgBox "Please select Valve from drop-down.", vbOKOnly + vbInformation, "Valve"
ValidateEntries = False
.cmbValve.BackColor = vbRed
.cmbValve.SetFocus
Exit Function
End If
If Trim(.txtFineFlow.Value) = "" Then
MsgBox "Please enter Fine Flow.", vbOKOnly + vbInformation, "Fine Flow"
ValidateEntries = False
.txtFineFlow.BackColor = vbRed
.txtFineFlow.SetFocus
Exit Function
End If
If Trim(.txtCoarseFLow.Value) = "" Then
MsgBox "Please enter Coarse Flow.", vbOKOnly + vbInformation, "Coarse Flow"
ValidateEntries = False
.txtCoarseFLow.BackColor = vbRed
.txtCoarseFLow.SetFocus
Exit Function
End If
If Trim(.txtintcoarseflow.Value) = "" Then
MsgBox "Please enter Int Coarse Flow.", vbOKOnly + vbInformation, " Int Coarse Flow"
ValidateEntries = False
.txtintcoarseflow.BackColor = vbRed
.txtintcoarseflow.SetFocus
Exit Function
End If
If Trim(.txtintfineflow.Value) = "" Then
MsgBox "Please enter Int Fine Flow.", vbOKOnly + vbInformation, "Int Fine Flow"
ValidateEntries = False
.txtintfineflow.BackColor = vbRed
.txtintfineflow.SetFocus
Exit Function
End If
End With
End Function
Currently, no field can be empty, when I hit save. My question is, how can I make it so that when Primed is selected and any other fields are empty it would auto writes N/A on the database when I click save?
Function ValidateEntries() As Boolean
ValidateEntries = True
Dim iMaterialID As Variant
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Print")
iMaterialID = frmForm.txtMaterialID.Value
With frmForm
'Default Color
.txtMaterialID.BackColor = vbWhite
.cmbValve.BackColor = vbWhite
.txtintfineflow.BackColor = vbWhite
.txtintcoarseflow.BackColor = vbWhite
.txtFineFlow.BackColor = vbWhite
.txtCoarseFLow.BackColor = vbWhite
.txtComments.BackColor = vbWhite
'--------------------------------
If Trim(.txtMaterialID.Value) = "" Then
MsgBox "Please enter Material ID.", vbOKOnly + vbInformation, "Material ID"
ValidateEntries = False
.txtMaterialID.BackColor = vbRed
.txtMaterialID.SetFocus
Exit Function
End If
'Validating Duplicate Entries
If Not sh.Range("B:B").Find(what:=iMaterialID, lookat:=xlWhole) Is Nothing Then
MsgBox "Duplicate Material ID found.", vbOKOnly + vbInformation, "Material ID"
ValidateEntries = False
.txtMaterialID.BackColor = vbRed
.txtMaterialID.SetFocus
Exit Function
End If
If Trim(.txtComments.Value) = "" Then
MsgBox "Please enter Comments.", vbOKOnly + vbInformation, "Comments"
ValidateEntries = False
.txtComments.BackColor = vbRed
.txtComments.SetFocus
Exit Function
End If
'Validating Scale
If .optLarge.Value = False And .optSmall.Value = False And .optBoth.Value = False Then
MsgBox "Please select Scale.", vbOKOnly + vbInformation, "Scale"
ValidateEntries = False
Exit Function
End If
If .CheckYes.Value = False And .CheckNo.Value = False Then
MsgBox "Please select Locked Yes or No.", vbOKOnly + vbInformation, "Locked"
ValidateEntries = False
Exit Function
End If
If .CheckYess.Value = False And .CheckNoo.Value = False Then
MsgBox "Please select Locked Yes or No.", vbOKOnly + vbInformation, "Locked"
ValidateEntries = False
Exit Function
End If
If Trim(.cmbValve.Value) = "" Then
MsgBox "Please select Valve from drop-down.", vbOKOnly + vbInformation, "Valve"
ValidateEntries = False
.cmbValve.BackColor = vbRed
.cmbValve.SetFocus
Exit Function
End If
If Trim(.txtFineFlow.Value) = "" Then
MsgBox "Please enter Fine Flow.", vbOKOnly + vbInformation, "Fine Flow"
ValidateEntries = False
.txtFineFlow.BackColor = vbRed
.txtFineFlow.SetFocus
Exit Function
End If
If Trim(.txtCoarseFLow.Value) = "" Then
MsgBox "Please enter Coarse Flow.", vbOKOnly + vbInformation, "Coarse Flow"
ValidateEntries = False
.txtCoarseFLow.BackColor = vbRed
.txtCoarseFLow.SetFocus
Exit Function
End If
If Trim(.txtintcoarseflow.Value) = "" Then
MsgBox "Please enter Int Coarse Flow.", vbOKOnly + vbInformation, " Int Coarse Flow"
ValidateEntries = False
.txtintcoarseflow.BackColor = vbRed
.txtintcoarseflow.SetFocus
Exit Function
End If
If Trim(.txtintfineflow.Value) = "" Then
MsgBox "Please enter Int Fine Flow.", vbOKOnly + vbInformation, "Int Fine Flow"
ValidateEntries = False
.txtintfineflow.BackColor = vbRed
.txtintfineflow.SetFocus
Exit Function
End If
End With
End Function