Validating Entries VBA

cmxulb

Board Regular
Joined
Nov 24, 2020
Messages
52
Office Version
  1. 365
Platform
  1. Windows
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?


1631882667522.png







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
 

Attachments

  • 1631881633707.png
    1631881633707.png
    24.1 KB · Views: 17
Yes! nice thanks man!..Yea CheckYes is "Locked"
When checked Yes for primed Valve type switches to N/A, How would you do it, so that it data is already there, don't change to N/A?

1632236252244.png


1632236267471.png
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Instead of this line:

VBA Code:
Me.cmbValve.Value = "N/A"

Use:

VBA Code:
If Me.cmbValve.ListIndex = -1 then Me.cmbValve.Value = "N/A"
 
Upvote 0
Do you mean if either Small or Large is checked do not check N/A (that was Both in the first image you posted)?
 
Upvote 0
Instead of:

VBA Code:
Me.optNA.Value = True

Use:

VBA Code:
If Me.optLarge.Value = False And Me.optSmall.Value = False Then Me.optNA.Value = True
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top