Open form on All conditions met

NigelShaw

Registered User.
Local time
Today, 20:27
Joined
Jan 11, 2008
Messages
1,572
Hi,

i am trying to open a form if all conditions are met. if the conditions are not met, then they get a flash message and then the user should return to the open form. i have the condition checking working but cannot seem to open the form if ALL conditions are true. i also need to close the form when the new form opens.how could i achieve this? here is my code

Private Sub MidVerifyContinue_Click()

FullNameChk.SetFocus

If FullNameChk = False Then
MsgBox "You Need to have a Full Name to Verify", vbOKOnly, "Message"
End If

If CompNameChk = False Then
MsgBox "You Need to have a Company Name to Verify", vbOKOnly, "Message"
End If

If TradeNameChk = False Then
MsgBox "You Need to have a Trading as name to Verify", vbOKOnly, "Message"
End If

If UTChk = False Then
MsgBox "You Need to have a number to Verify", vbOKOnly, "Message"
End If

If CRChk = False Then
MsgBox "You Need to have a C R number to Verify", vbOKOnly, "Message"
End If

If NIChk = False Then
MsgBox "You Need to have a N I number to Verify", vbOKOnly, "Message"
End If

If PostCodeChk = False Then
MsgBox "You Need to have a Postcode to Verify", vbOKOnly, "Message"
End If

Exit Sub


DoCmd.OpenForm "New Verification Qry"

End Sub


many thanks,

Nigel
 
Delete the Exit Sub statement and put it after every msgbox within If..End If statements in your VBA Code.

zaqyu
 
It is easier to read code if it has been enclosed within code tags. Here's one possible solution for you.
Code:
Private Sub MidVerifyContinue_Click()

   FullNameChk.SetFocus

   If FullNameChk = False Then
      MsgBox "You Need to have a Full Name to Verify", vbOKOnly, "Message"
      Exit Sub
   End If

   If CompNameChk = False Then
      MsgBox "You Need to have a Company Name to Verify", vbOKOnly, "Message"
      Exit Sub
   End If

   If TradeNameChk = False Then
      MsgBox "You Need to have a Trading as name to Verify", vbOKOnly, "Message"
      Exit Sub
   End If

   If UTChk = False Then
      MsgBox "You Need to have a number to Verify", vbOKOnly, "Message"
      Exit Sub
   End If

   If CRChk = False Then
      MsgBox "You Need to have a C R number to Verify", vbOKOnly, "Message"
      Exit Sub
   End If

   If NIChk = False Then
      MsgBox "You Need to have a N I number to Verify", vbOKOnly, "Message"
      Exit Sub
   End If

   If PostCodeChk = False Then
      MsgBox "You Need to have a Postcode to Verify", vbOKOnly, "Message"
      Exit Sub
   End If

   DoCmd.OpenForm "[New Verification Qry]"
   DoCmd.Close acForm, Me.Name, acSaveNo

End Sub
 
Hi,

i had already tried that. i need all unchecked items to flash up a message if it is not ticked and then cancel the code but ONLY if all boxes are ticked will it open the next form. putting Exit sub after every message within the If statement cancels the code after every tick box check. unless there is a way of pooling the unchecked items to show on one form together.

regs,

NS
 
Hi,

i had already tried that. i need all unchecked items to flash up a message if it is not ticked and then cancel the code but ONLY if all boxes are ticked will it open the next form. putting Exit sub after every message within the If statement cancels the code after every tick box check. unless there is a way of pooling the unchecked items to show on one form together.

regs,

NS

Nigel -

I don't think you tried RG's code exactly because if you did you would find that it will work. It will not let you to the form open unless all checkboxes are checked.
 
Hi Bob,

i di try the code and it does so what you explain but it wasnt how i wanted it to work. currently, the code will check the values of the Check boxes and if the values are false, then close without opening the form but this will only happen in sequence and close the code on the next un ticked box. i need it to check the values, the flash a msgbox for ALL values to prompt the user to get the info before proceeding. so in esscence you would tick 4 out of 7 boxes and press continue. you would then get 3 pop up messages telling what is needed. an alternative would be 1 message showing all values.

i will post what i have done so far as i am progresing slightly.

NS
 
Maybe this is what you are looking for:
Code:
Private Sub MidVerifyContinue_Click()

   Dim StopTest As Boolean

   If FullNameChk = False Then
      MsgBox "You Need to have a Full Name to Verify", vbOKOnly, "Message"
      StopTest = True
   End If

   If CompNameChk = False Then
      MsgBox "You Need to have a Company Name to Verify", vbOKOnly, "Message"
      StopTest = True
   End If

   If TradeNameChk = False Then
      MsgBox "You Need to have a Trading as name to Verify", vbOKOnly, "Message"
      StopTest = True
   End If

   If UTChk = False Then
      MsgBox "You Need to have a number to Verify", vbOKOnly, "Message"
      StopTest = True
   End If

   If CRChk = False Then
      MsgBox "You Need to have a C R number to Verify", vbOKOnly, "Message"
      StopTest = True
   End If

   If NIChk = False Then
      MsgBox "You Need to have a N I number to Verify", vbOKOnly, "Message"
      StopTest = True
   End If

   If PostCodeChk = False Then
      MsgBox "You Need to have a Postcode to Verify", vbOKOnly, "Message"
      StopTest = True
   End If

   If Not StopTest Then
      DoCmd.OpenForm "[New Verification Qry]"
      DoCmd.Close acForm, Me.Name, acSaveNo
   End If

End Sub
 
Hi RG,

thank you for that. i had in the meantime changed the format to flash only 1 box with all items listed that had a value of False. by the time you placed your code, it would have meant hours of re writing other stuff but thnak you anyway.
FYI
i made a code that looked at the 7 check boxes and created a variable that value was set to 1 if the checkbox was true.
if main variable = 7, the designated form was opened. if it was less than 7, the checkboxes with a false value were shown on a form that was set to to check the checkboxes and become visible if False but hidden if True.

hope that makes sense. only written for the purpose of everyone in the future.


Nigel
 
Glad you got it sorted. As Linq is fond of saying: There is more than one way to skin a cat.
 

Users who are viewing this thread

Back
Top Bottom