Hello!
Can I make a field required only when the field is visible (using VBA)? I don't see a .required property.......
Hello!
Can I make a field required only when the field is visible (using VBA)? I don't see a .required property.......
In the form text box, you can set
VALIDATION RULE (and VALIDATION TEXT if they dont follow it)
or yes, since you want it 'sometimes' you can put in a check when they hit save...
Code:btnSave_click() if IsValidForm() then SAVErec() end if end sub public Function IsValidForm() as boolean dim vMsg select case true case txtName = "" and txtName.visible vMsg = "Client Name is missing" case isnull(cboState ) vMsg = "State is missing" cboState.setfocus end select if vMsg <>"" then msgbox vmsg,vbCritical,"Required" IsValidForm =vMsg ="" end sub
You can use code in the Form_BeforeUpdate event to
- See if the TextBox is Visible
- See if it has been populated, if Visible
- Cancel the Update if #1 is True and #2 is False
- Warn the user
- Return Focus to the Control
Where SometimesRequired is the name of the Textbox in question:
Code:Private Sub Form_BeforeUpdate(Cancel As Integer) If (Me.SometimesRequired.Visible = True) And (Nz(Me.SometimesRequired, "") = "") Then Cancel = True MsgBox "The SometimesRequired Field Must be Populated When Visible!" SometimesRequired.SetFocus End If End Sub
Linq ;0)>
Thanks! This worked....how do I mark as solved?
Glad we could help!
Have no idea how to mark a thread as 'solved!' I've never actually posted a question, here, but expect that there is a tool, maybe only visible to the original poster, for doing so...maybe under the "Preview Post" button?
Linq ;0)>