Solved

Accepting a value with If statement VBA

Posted on 2014-12-31
6
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

735 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