Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2017
    Posts
    7

    Answered: If statement is not functioning

    My If statement is not functioning correctly. I have entered values for all required fields but it still shows the first message box. I also decompiled.

    If (IsNull(txtSLD_Number.Value) Or txtSLD_Number.Value = "" Or IsNull(txtPurpose.Value) _
    Or txtPurpose.Value = "" Or IsNull(txtEvent.Value) Or txtEvent.Value = "" Or _
    IsNull(txtService_Recipient.Value) Or txtService_Recipient.Value = "" Or _
    IsNull(Forms!SLD![Town Subform].Form!txtTown.Value) Or _
    Forms!SLD![Town Subform].Form!txtTown.Value = "" Or _
    IsNull(Forms!SLD![Town Subform].Form!txtSLD_Recipient.Value) Or _
    Forms!SLD![Town Subform].Form!txtSLD_Recipient.Value = "") Then

    MsgBox ("Ensure you have entered values for the following fields: SLD Number, Purpose, " _
    & " Event, Service Recipient, SLD recipient and Town.") ',vbExclamation,"Values required")

    txtSLD_Number.SetFocus

    ElseIf (Len(txtSLD_Number.Value) <> 15) Then
    MsgBox ("SLD number should be 15 digits long.")

    ElseIf (IsNumeric(Forms!SLD![Town Subform].Form!txtSLD_Recipient.Value) = False) Then

    MsgBox ("SLD recipient must be numeric.")

    Else

    DoCmd.RunCommand acCmdSaveRecord
    MsgBox ("Record Saved.")
    End If

  2. Best Answer
    Posted by ridders

    "
    Quote Originally Posted by MARCUSM View Post
    My If statement is not functioning correctly. I have entered values for all required fields but it still shows the first message box. I also decompiled.

    If (IsNull(txtSLD_Number.Value) Or txtSLD_Number.Value = "" Or IsNull(txtPurpose.Value) _
    Or txtPurpose.Value = "" Or IsNull(txtEvent.Value) Or txtEvent.Value = "" Or _
    IsNull(txtService_Recipient.Value) Or txtService_Recipient.Value = "" Or _
    IsNull(Forms!SLD![Town Subform].Form!txtTown.Value) Or _
    Forms!SLD![Town Subform].Form!txtTown.Value = "" Or _
    IsNull(Forms!SLD![Town Subform].Form!txtSLD_Recipient.Value) Or _
    Forms!SLD![Town Subform].Form!txtSLD_Recipient.Value = "") Then

    MsgBox ("Ensure you have entered values for the following fields: SLD Number, Purpose, " _
    & " Event, Service Recipient, SLD recipient and Town.") ',vbExclamation,"Values required")

    txtSLD_Number.SetFocus

    ElseIf (Len(txtSLD_Number.Value) <> 15) Then
    MsgBox ("SLD number should be 15 digits long.")

    ElseIf (IsNumeric(Forms!SLD![Town Subform].Form!txtSLD_Recipient.Value) = False) Then

    MsgBox ("SLD recipient must be numeric.")

    Else

    DoCmd.RunCommand acCmdSaveRecord
    MsgBox ("Record Saved.")
    End If
    Your first msgbox code has a single quote before the comma. Replace with ".
    Also the brackets aren't needed

    Suggest you rewrite each part of the If section using Nz"


  3. #2
    Join Date
    Apr 2017
    Posts
    2
    Provided Answers: 1
    Quote Originally Posted by MARCUSM View Post
    My If statement is not functioning correctly. I have entered values for all required fields but it still shows the first message box. I also decompiled.

    If (IsNull(txtSLD_Number.Value) Or txtSLD_Number.Value = "" Or IsNull(txtPurpose.Value) _
    Or txtPurpose.Value = "" Or IsNull(txtEvent.Value) Or txtEvent.Value = "" Or _
    IsNull(txtService_Recipient.Value) Or txtService_Recipient.Value = "" Or _
    IsNull(Forms!SLD![Town Subform].Form!txtTown.Value) Or _
    Forms!SLD![Town Subform].Form!txtTown.Value = "" Or _
    IsNull(Forms!SLD![Town Subform].Form!txtSLD_Recipient.Value) Or _
    Forms!SLD![Town Subform].Form!txtSLD_Recipient.Value = "") Then

    MsgBox ("Ensure you have entered values for the following fields: SLD Number, Purpose, " _
    & " Event, Service Recipient, SLD recipient and Town.") ',vbExclamation,"Values required")

    txtSLD_Number.SetFocus

    ElseIf (Len(txtSLD_Number.Value) <> 15) Then
    MsgBox ("SLD number should be 15 digits long.")

    ElseIf (IsNumeric(Forms!SLD![Town Subform].Form!txtSLD_Recipient.Value) = False) Then

    MsgBox ("SLD recipient must be numeric.")

    Else

    DoCmd.RunCommand acCmdSaveRecord
    MsgBox ("Record Saved.")
    End If
    Your first msgbox code has a single quote before the comma. Replace with ".
    Also the brackets aren't needed

    Suggest you rewrite each part of the If section using Nz

  4. #3
    Join Date
    Jun 2017
    Posts
    7

    If statement not functioning continues

    This one is also returning true for both conditions:

    If (IsNumeric(Forms!Payments![Payment subform].Form!txtPayment_Number.Value) = False Or _
    Len(Forms!Payments![Payment subform].Form!txtPayment_Number.Value <> 7)) Then

  5. #4
    Join Date
    Apr 2017
    Posts
    2
    Provided Answers: 1
    This wasn't part of your original post...

    Quote Originally Posted by MARCUSM View Post
    This one is also returning true for both conditions:

    If (IsNumeric(Forms!Payments![Payment subform].Form!txtPayment_Number.Value) = False Or _
    Len(Forms!Payments![Payment subform].Form!txtPayment_Number.Value <> 7)) Then
    It will do so if txtPayment_Number.Value isn't a number or if its length is anything other than 7
    e.g. A12345 or 012345 will both give true to both parts of the condition

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •