Results 1 to 15 of 15
  1. #1
    sanderson is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    64

    dLookup Syntax in Access for form checkbox control source

    Hello:

    Well here we go, and I'm sure I am missing the obvious. Why won't this work?

    Code:
    =DLookUp("[approved]","[tblocalApprovalLog]", “[dayDate] =‘” & [Forms]![frmTimeCard].[txtDate] & “’ And "[weekDate] =‘" & [Forms]![frmTimeCard].[txtPeriodStart] & " - " & [Forms]![frmTimeCard].[txtPeriodEnd] & "’ And [empid]='" & [txtEmployeeNo] & "'")
    In contract, this does, and I've just added one more field to the mix. The error is invalid syntax, operand without an operator...



    Code:
    =DLookUp("[approved]","[tblocalApprovalLog]","[weekDate] between #" & [Forms]![frmTimeCard].[txtPeriodStart] & "# And #" & [Forms]![frmTimeCard].[txtPeriodEnd] & "# And [empid]='" & [txtEmployeeNo] & "'")

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    What is the Text Format property of your control that has the expression? In the Property Sheet and under the Data tab is the Text Format property. It should be Plain Text for expressions. You do not want to use Rich Text as an option for the Text Format Property.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    In addition to ItsMe's comment, you have some strange quote symbols in your code
    =DLookUp("[approved]","[tblocalApprovalLog]", [dayDate] =‘” & [Forms]![frmTimeCard]......
    From my experience Access uses ' and ".

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Your first statement shows odd " and ' marks (slanted, italics). How did those get in there? Access won't like them.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    sanderson is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    64
    I removed all the wierd quotation characters. Because I wrote these in Microsoft Word, which likes to interchange the quotation characters, this was the result. Regardless, it still is not happy with me and when I paste it in I get the same issue...

    Click image for larger version. 

Name:	Untitled.png 
Views:	10 
Size:	16.0 KB 
ID:	21753

    Code:
    =DLookUp("[approved]","[tblocalApprovalLog]", "[dayDate] ='" & [Forms]![frmTimeCard].[txtDate] & "' And "[weekDate] ='" & [Forms]![frmTimeCard].[txtPeriodStart] & " - " & [Forms]![frmTimeCard].[txtPeriodEnd] & "' And [empid]= '" & [txtEmployeeNo] & "' ")

  6. #6
    sanderson is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    64
    Perhaps the confusion is that there are too many quotes to begin with. I am entering this directly into the Control Source for the checkbox, not through code. When I try to use the expression builder, it adds all kinds of stuff. Perhaps I do not need all the quotes, but do I need them for the constants?

    Code:
    =DLookUp("[approved]","[tblocalApprovalLog]", "[dayDate] ='" & [Forms]![frmTimeCard].[txtDate] & "' And "[weekDate] ='" & [Forms]![frmTimeCard].[txtPeriodStart] & " - " & [Forms]![frmTimeCard].[txtPeriodEnd] & "' And [empid]= '" & [txtEmployeeNo] & "' ")

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Dates should be enclosed with octothorpes (hash marks #),
    Strings should be enclosed in quotes '
    Numbers do not require special enclosing punctuation.

  8. #8
    sanderson is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    64
    While this information does represent a date, the data type is a string in the table. The question is, what is the difference between coding a dLookup in Access VBA vs placing (hardcoding) it directly in the control?

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    ???Not sure I'm following??

    You would use a DLookup with some criteria to make the process generic/reusable.
    If you hard code anything, you have removed reusability.

  10. #10
    sanderson is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    64
    What I mean by hardcoding is entering it directly into the control source property on the form, rather than building the string in VBA.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    A date represented by a string will not work for filtering by a range. The " - " in criteria is meaningless. There is also an extra " mark in front of [weekDate].

    =DLookUp("[approved]","[tblocalApprovalLog]", "[dayDate] ='" & [Forms]![frmTimeCard].[txtDate] & "' And CDate([weekDate]) BETWEEN #" & [Forms]![frmTimeCard].[txtPeriodStart] & "# AND #" & [Forms]![frmTimeCard].[txtPeriodEnd] & "# And [empid]= '" & [txtEmployeeNo] & "' ")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    sanderson is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    64
    The reason why the dash is necessary is that it is looking at a string with the dash incorporated into it.

    Perhaps this changes my dLookup??

    Code:
    =DLookUp("[approved]","[tblocalApprovalLog]","[dayDate] ='" & [Forms]![frmTimeCard].[txtDate] & "' And [weekDate] = '" & [Forms]![frmTimeCard].[txtPeriodStart] & " - " & [Forms]![frmTimeCard].[txtPeriodEnd] & "' And [empid]= '" & [txtEmployeeNo] & "' ")
    But what I still do not get, is why the form displays the square dots instead of the actual value. There is code for when approve is clicked and the Submit totals button is pressed to check the approved column.

    I also tried just setting the control source to the field, and got the same result.

    Thoughts? And much thanks!
    Attached Thumbnails Attached Thumbnails data.png  

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Okay, got it. Your original expression should work. But I can't test because TimeCards table is not available. Can't open frmTimeCard. Would have to do too much modifying of db to get this to run.

    What 'square dots' - an oxymoron, can dots be square?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    sanderson is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    64
    The square dots in the checkbox column in the Approved column...
    Attached Thumbnails Attached Thumbnails form.png  

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    That does happen with UNBOUND checkboxes and all records will show the same value.

    This issue is closely related to your other thread. https://www.accessforums.net/forms/b...orm-54498.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Syntax error in control source of text box
    By shaunacol in forum Forms
    Replies: 7
    Last Post: 07-16-2015, 04:55 AM
  2. Dlookup as control source on continuous form.
    By Ramun_Flame in forum Programming
    Replies: 4
    Last Post: 10-24-2012, 10:26 AM
  3. DLookup in Control Source
    By bgephart in forum Forms
    Replies: 2
    Last Post: 08-28-2012, 02:06 PM
  4. DLookup() for Text Box Control Source
    By tylerg11 in forum Forms
    Replies: 3
    Last Post: 02-06-2012, 02:21 PM
  5. Dlookup as Control Source
    By alsoto in forum Forms
    Replies: 1
    Last Post: 08-28-2011, 07:05 PM

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