Solved

Accepting a value with If statement VBA

Posted on 2014-12-31
6
167 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

910 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