Results 1 to 4 of 4
  1. #1
    Lockrin is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    52

    DLookup for Yes/No field

    Hello all, I would like to do a DLookup to reference a Yes/No field in my VBA code. My problem is that I don't know what to reference it as. I want to use something like



    Dim iBeamNumber As Integer
    Dim stWhere As String '-- Criteria for DLookup
    Dim stYesNo As "I don't know what to put here"

    iBeamNumber = Me.BeamNumber

    stWhere = "[qryBeamNumberNeeded].[BeamNumber] = " & "'" & iBeamNumber & "'"
    stYesNo = DLookup("[EmailNeeded]", "qryBeamNumberNeeded", stWhere)


    The rest of my code will be used to send an email based on the value of the Yes/No field. I also need to know what value it will return (Usually it is "-1" for true and "0" for false)

    Thanks in advance

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The variable data type equivalent of Yes/No is Boolean. Be careful though, since if the DLookup() can't find a value, it will return Null, and the only type that can handle Null is Variant. You could get around that by wrapping the DLookup() in the Nz() function as well.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Lockrin is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2009
    Posts
    52
    That is giving me error 3464 "Data type mismatch in criteria expression."
    Here is exactly what I have



    Dim iShipment As Integer '-- Reference to tblStopCardDeviations
    Dim stWhere As String '-- Criteria for DLookup
    Dim stStamp As Boolean

    iShipment = Me.Shipment_Number

    stWhere = "[qryShipmentRequirements].[Shipment Number] = " & "'" & iShipment & "'"
    stStamp = Nz(DLookup("[SDI]", "qryShipmentRequirements", stWhere))

    If stStamp = "-1" Then
    Me.SDIStampLabel1.Visible = False
    Else
    Me.SDIStampLabel1.Visible = False
    End If

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If the data type of [Shipment Number] is numeric, you don't want the single quotes around the value:

    DLookup Usage Samples
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Need help with dlookup.
    By Keith in forum Database Design
    Replies: 8
    Last Post: 05-24-2010, 06:28 PM
  2. Replies: 4
    Last Post: 03-05-2010, 09:56 PM
  3. Dlookup??
    By Vikki in forum Access
    Replies: 4
    Last Post: 02-16-2010, 07:59 AM
  4. Dlookup problem
    By CalifDan in forum Reports
    Replies: 4
    Last Post: 12-09-2009, 06:09 AM
  5. Dlookup
    By janjan_376 in forum Access
    Replies: 20
    Last Post: 07-07-2009, 07:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums