Solved

Accepting a value with If statement VBA

Posted on 2014-12-31
6
165 Views
Last Modified: 2014-12-31
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
Comment
Question by:Ernest Grogg
  • 3
  • 2
6 Comments
 
LVL 84
ID: 40525909
You'll have to further define what you mean by "accept", and explain exactly what you're trying to do.
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40525929
Maybe

Cancel = FALSE

or just


Open in new window


That's right - absolutely nothing could also work.
0
 

Author Comment

by:Ernest Grogg
ID: 40525944
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 84
ID: 40525961
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
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40525967
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
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40525979
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now