String Array for Required.

musclecarlover07

Registered User.
Local time
Yesterday, 20:26
Joined
May 4, 2012
Messages
236
Ok at one point I had the code but I can't fint the project that has the code I needed. :banghead::mad:.

Basically I need to make fields: Street, City, ST, Zip required fields if Status have value of D or SD. Then when I go to exit the form "QuickUpdater" if any iof these fields are blank when the status has value of D or SD then a mesgbox will pop up stating such field is required. Like I said I had it at one point an it was setup so I put all the fields that were needed to be required were in the string then it would go an check each field to see if it had a value if not then the message box poped up. I need to duplicate this method again...
 
You can Add to the Tag property some value and in the beforeUpdate or whatever event closing the task , you can check for this value
 
From that page:

There are a number of scenarios that share the same solution. In general, data validation is best done in the before update event of your form. That presumes the form is bound to a table or query of course. You may want to make sure certain fields are filled out, that dates meet certain criteria, or you may have fields that only need to be filled out based on the contents of other fields.

Note that as is often the case, there are other ways to solve some of these issues. In the case of data validation, you can also use field properties such as required, validation rules, etc, but those are not the focus of this page.

The beauty of the before update event is that it can be cancelled, using "Cancel = True" in your code. This stops the update from occurring and leaves the user on the form. The code might look something like this:

Code:
If Len(Me.SomeControl & vbNullString) = 0 Then
  MsgBox "You need to fill out SomeControl"
  Cancel = True
  Me.SomeControl.SetFocus
End If
 
I mean I have seen that and thats not exactly what I was going for. What i remember was when I had the code it had multiple field names listed in the string then it would look for them all at once. Then the msgbox would say "Field name" is required then set focus. I remember also having to set a string then it would check the string. I mean this will work if i can add multiple fields. I want it to do the check when I click the close button. So it checks all at once. Also I only need the fields to be required if the status have certain value.
Code:
If Me.Status__Initial_.Value Or Me.Combo14.Value = "D" Or "SD" And Me.Agent.Value <> "ME" Then
Me.Street = Required

This is what I had before i started. If im reading right then this states if Status Initial or Combo 14 have values of D or SD and Agent does not equal Me then do the following...

Idk if puttintg
Code:
Me.Street = Required
Makes the field required.
 
This is what I have so far. It works but its not 100% what I need/want
Code:
Dim AddressCheck As Variant
AddressCheck = Array(Me.ST.Name, Me.Zip.Name)
If Forms!Customer_Data!JPPSO_Data.Form![Status (Initial)].Value = "SD" Then
If Len(Me.ST & vbNullString) = 0 Then
MsgBox "is REQUIRED", vbOKOnly, "REQUIRED"
Else
DoCmd.Close acForm
End If
End If
Basically I need for it to check to see if the the 2 fields have a value. If not then a message box pops up and says the Field name is required. I figured out how to get the field name thats why in the array they are the way they are but I want it to use the array to see what does not have a value. THen based on that it tells you what field is empty. Then set focus. I got the set focus down. I hope this makes sense. :banghead::banghead::banghead::confused::confused::confused:
 
I wouldn't bother with an array, I'd test each in turn:

Code:
If Len(Me.ST & vbNullString) = 0 Then
  'do something
End If

If Len(Me.Zip & vbNullString) = 0 Then
  'do something
End If

You can exit the code after the first failed control, or build a string with all that failed.
 
This may work better then the array I was referring to. Cause the array just checked to see if the the values were blank. This way i have to check 3 other field values and go from there. So far all is going well.
 
I have Cancel = True and its still closing the form. Is there something else that I am missing? On my my close button I have this:

Private Sub cboCloseAdd_Click()
DoCmd.Save
DoCmd.Close
Forms![Helena Employees].Requery
End Sub
 
Where do you have it? The Save line is probably not doing what you think it is. ;)
 
Its in the on click event for the button. Should I have it close another way?
 
Yep figured it out. Was the save line.
 

Users who are viewing this thread

Back
Top Bottom