Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

Accepting a value with If statement VBA

Hello,

I have the following Code but can't remember how to accept the value in the first IF statement

 
         
    If Forms!frmMG3055_1a!BadgeIssued = "3055" Then
       ACCEPT THIS VALUE  BUT IF THE DCOUNT NEXT MATCHES ANY OTHER NUMBER (THIS IS WHERE I PUT THE ELSE)
    Else
       If DCount("BadgeIssued", "qryBadgeTimeOutNull") > 0 Then
   
         MsgBox "Please Enter a Different Badge as that badge is already assigned to a customer...and You must sign out the badge first", vbOKOnly
         Cancel = True
         Me.BadgeIssued.SetFocus
         Exit Sub
       Else
             If DCount("LicenseNumber", "qryMGLicenseDup") > 0 Then
                If MsgBox("This License # appears to be already in the system.  Would you like to edit the License #?", vbYesNo) = vbYes Then
                Me.LicenseNumber.SetFocus
                        Cancel = True
                        Exit Sub
                Else
                MsgBox "I will undo the record and open box to search for customer", vbOKOnly
                        Me.Undo
                        DoCmd.OpenForm "frmLicense"
                End If
             End If
         End IF
         
    End If
0
Ernest Grogg
Asked:
Ernest Grogg
  • 3
  • 2
1 Solution
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You'll have to further define what you mean by "accept", and explain exactly what you're trying to do.
0
 
Phillip BurtonCommented:
Maybe

Cancel = FALSE

or just


Open in new window


That's right - absolutely nothing could also work.
0
 
Ernest GroggAuthor Commented:
I guess what I am looking for is that

 If DCount("BadgeIssued", "qryBadgeTimeOutNull") > 0

'And the Form Control has "3055"  THEN  MOVE on to the next DCount

If DCount("LicenseNumber", "qryMGLicenseDup") > 0 Then
             If MsgBox("This License # appears to be already in the system. Would you like to edit the License #?", vbYesNo) = vbYes Then
                   Me.LicenseNumber.SetFocus
                   Cancel = True
                   Exit Sub
            Else
                    MsgBox "I will undo the record and open box to search for customer", vbOKOnly
                    Me.Undo
                    DoCmd.OpenForm "frmLicense"
                    End If
Else
            MsgBox "Please Enter a Different Badge as that badge is already assigned to a customer...and You must sign out the badge first", vbOKOnly
                Cancel = True
                Me.BadgeIssued.SetFocus
                Exit Sub
End if


so if the first DCount returns a "greater than Zero" and the Control on the Form has "3055" then Move on Else MSGBox "Please Enter....."
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Perhaps this:

If DCount("BadgeIssued", "qryBadgeTimeOutNull") > 0 AND Forms!frmMG3055_1a!BadgeIssued = "3055" Then
  If DCount("LicenseNumber", "qryMGLicenseDup") > 0 Then
    etc etc
Else
   MsgBox "Please Enter a Different Badge as that badge is already assigned to a customer...and You must sign out the badge first", vbOKOnly
  etc etc
End If
0
 
Phillip BurtonCommented:
I don't think your problem is the one stated; I don't know why you need to move on.

If you need to move on to the next record, then use DoCmd.GotoRecord

You need to use the third criteria in the DCount - the criteria, I.e.

DCount("BadgeIssued", "qryBadgeTimeOutNull", "badgeissued = " & Forms!frmMG3055_1a!BadgeIssued)
0
 
Phillip BurtonCommented:
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now