Solved

Accepting a value with If statement VBA

Posted on 2014-12-31
6
177 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

710 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