coasterman
Registered User.
- Local time
- Today, 12:07
- Joined
- Oct 1, 2012
- Messages
- 59
I have a validation routine behind cmd button 1.
I also have a second cmd button which launches the code starting at 'LimitationPeriod......"
I was trying to combine the two bits of code to save a second cmd button but I am finding that once once code in the first part finds the first blank field it Exit for.. and carries on with the second chunk of code.
As that second chunk of code launches an excel sheet whose values are dependent on validated data in the first half of the code it's simply not fit for purpose.
I had some nonsense idea that if I could set a variable i to keep track of when validation failed it would let me exit the sub after the focus had been set to the empty control. That was as I've found not going to work, or at at least if it has some potential I have stuff in the wrong order?
What I am looking for is for the sub to exit after it finds the first invalid (in this case empty field" so it doesnt carry on after the For Next loop and launch the spreadsheet.
I thought I had this sorted in Excel but seems things are quite so simple in Access
Thanks for looking
Code:
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
If Mid(ctl.Tag, 3, 1) = "£" And Trim(ctl & "") = "" Then
' i = 1 (my hairbrain idea)
msg = "Data Required for '" & ctl.Name & "' field!" & nl & _
"You can't save this record until this data is provided!" & nl & _
"Enter the data and try again . . . "
Style = vbCritical + vbOKOnly
Title = "Required Data..."
MsgBox msg, Style, Title
ctl.SetFocus
Cancel = True
' If i = 0 Then GoTo Limitation (hairbrain idea cont.)
Exit For
End If
End If
Next
' the bit I want to get to once all controls meet validation
Limitation:
LimitationPeriod = 1095
If Not IsNull(Me.DateofAcc) Then
DaysSinceRTA = DateDiff("d", Me.[DateofAcc], Date)
etc.......
I also have a second cmd button which launches the code starting at 'LimitationPeriod......"
I was trying to combine the two bits of code to save a second cmd button but I am finding that once once code in the first part finds the first blank field it Exit for.. and carries on with the second chunk of code.
As that second chunk of code launches an excel sheet whose values are dependent on validated data in the first half of the code it's simply not fit for purpose.
I had some nonsense idea that if I could set a variable i to keep track of when validation failed it would let me exit the sub after the focus had been set to the empty control. That was as I've found not going to work, or at at least if it has some potential I have stuff in the wrong order?
What I am looking for is for the sub to exit after it finds the first invalid (in this case empty field" so it doesnt carry on after the For Next loop and launch the spreadsheet.
I thought I had this sorted in Excel but seems things are quite so simple in Access

Thanks for looking