Results 1 to 6 of 6
  1. #1
    doomy304 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    6

    Expression issues

    Hello,

    I have two tables. One is Agents, with fields AgentName (text) and ExpirationDate (date/time). The other table is Hours, with fields AgentName (linked to Agents), HoursDate (date/time), and HoursNumber (number).

    I have a data entry form for the Hours table, and I have a Save Record button on it, and when the user clicks the Save Record button, I want it to check to see whether the HoursDate is before or after the ExpirationDate linked to that same agent and take action accordingly.

    I'm using a macro to do this but I am open to VB if that would be easier.

    I tried If Agents![ExpirationDate] > [HoursDate] Then blahblah but that popped up syntax error. Then I tried If [HoursDate]-Agents![ExpirationDate] > 0 Then blahblah but that also gave me syntax error.



    I am sure I am missing something obvious here. Please help!

  2. #2
    doomy304 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    6
    The "blahblah" is just message boxes, by the way, so I'm pretty sure the syntax error is not coming from that.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can't refer to an unrelated table that way (a table not included in the record source of the form). You can use DLookup() or open a recordset to get the value. Here's the DLookup syntax:

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

  4. #4
    doomy304 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    6
    Thanks, that really helps! But I am still getting the invalid syntax error.

    Here is what I have now:

    If DLookup("[ExpirationDate]","Agents","[AgentName] = Forms![FormName]![AgentName]") > [HoursDate] Then messagebox

    I am pretty sure at this point it's a brackets/quotes issue, right?
    Last edited by doomy304; 07-02-2011 at 09:44 AM. Reason: missed a quote

  5. #5
    doomy304 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    6
    OK, fixed one issue - had spaces in my form name, renamed the form to be spacefree and now I am getting error Data type mismatch in criteria expression which is an improvement I think!

    edit: FIGURED IT OUT!!! The problem was that due to the way I had my lookups set up, [AgentName] in the Agents table was a text field, and [AgentName] in the form was a number. So I switched it to

    DLookUp("[ExpirationDate]","Agents","[ID] = " & [Forms]![FormName]![AgentName])>[HoursDate]

    and now it is doing exactly what I want YESSSS

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Glad you got it sorted out.
    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. Date expression issues
    By QTip in forum Queries
    Replies: 4
    Last Post: 01-06-2011, 03:43 PM
  2. Pagination issues
    By stupesek in forum Reports
    Replies: 2
    Last Post: 09-01-2010, 10:43 AM
  3. Message box issues.
    By thart21 in forum Programming
    Replies: 2
    Last Post: 05-29-2010, 12:58 AM
  4. Replies: 1
    Last Post: 03-23-2010, 04:01 PM
  5. Replies: 0
    Last Post: 03-11-2009, 11: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