Results 1 to 11 of 11
  1. #1
    TriFith is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Czech republic, Prague
    Posts
    37

    macro - IF [query] = "1234" then ...

    Hello everyone,
    I found a problem in one of my databases, which seems to be very simple, but I didnīt find how to run it.
    I would like to ask you for help with my problem.

    I need to do very special macro, which should run a querry and decide what to da regarding the result.

    I have a table called "tblList" and one of the columns is logical type called "ActuallStatus".
    I also have a querry "qryActualStatus":
    Code:
    SELECT tblList.ActuallStatus FROM List WHERE (((tblList.ID)=[Enter ID:]));
    This querry has an actuall status of row with entered ID as a result. So there are only two possible results... TRUE/FALSE

    Now I need to write a macro which should choose between submacros regarding the result of querryActuallStatus. I tried several ways how to da that, but I failed everytime. For example here is on of my attempts:
    Code:
    IF [qryActuallStatus]![ActuallStatus] = 0 then
       ...submacro1
    ELSE
       ...submacro2
    END IF
    All of my attempts stuck on the same step. Access always throws an error call, where it says its not able to find object qryActuallStatus.

    Can you please advice me how to make this macro?


    Thank you very much

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can't refer to the query value that way. Simplest is probably a DLookup().
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    TriFith is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Czech republic, Prague
    Posts
    37
    Thank you advice!
    Itīs working great with DLookup function.

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help, and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    TriFith is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Czech republic, Prague
    Posts
    37
    Thank you for welcome!
    Unfortunatelly I stucked on other problem
    I am really not to skilled with access programming, I prefer php ot C# programming. So, more than likely I am asking like like noob to very simple questions...
    Mu current problem is a login to form...
    I have table with list of operators and in a start form i have text box with login. Users have to enter their access code (4 nums) to identify themselves.
    Again I need to do macro which will verify if entered code exists as a first step...
    I tried to use DLookUp function with IsNull function, but this macro is not functional

    If IsNull(DLookUP("[tblOperators]![AccessCode]";"[tblOperators]";"[tblOperators]![AccessCode] = [Forms]![frmStart]![login]") )
    Then.........

    Can you help me once more please?

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    For starters, try this syntax:

    http://access.mvps.org/access/general/gen0018.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    TriFith is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Czech republic, Prague
    Posts
    37
    Hi,
    Finally I found out how to solve my problem.
    I tried to use syntax from your link, but it didnīt work. It was throwing an error during preceeding the macro.

    Final solution of my problem is:
    Code:
    If IsNull(DLookUp("Name";"tblOperators";"AccessCode=[Forms]![frmUse]![AccessCode]"))
    I have no idea why this is working, but I can move forward now
    Thank you for inspiration and your time.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,924
    No, that CANNOT be working. You have enclosed variable within quotes and using semi-colons instead of commas. Assuming AccessCode is a text field:

    If IsNull(DLookUp("[Name]","tblOperators","AccessCode='" & [Forms]![frmUse]![AccessCode] & "'")) Then
    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.

  9. #9
    TriFith is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Czech republic, Prague
    Posts
    37
    I know it shouldnīt be working like that, but it is working... Believe me, I am not joking.
    But I tried also your expression too. Access was not able to save this macro, and then I watched the mistake... There should be semicolon instead of comma between parameters of function DLookUp :-D
    With semicolons your expression is working too.

    But it is a little mistery for me, why my "primitive" expression is working

    Thank you all for help!

  10. #10
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I have seen it work with the form reference inside the quotes, but I've never seen it fail when properly concatenated.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,924
    You are doing this in a macro, not VBA? That might explain it. I don't use macros.
    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. How do I program a "For 1 to X" type loop in a macro?
    By msmithtlh in forum Programming
    Replies: 7
    Last Post: 04-16-2013, 10:49 AM
  2. Export "Query or Report" to a "Delimited Text File"
    By hawzmolly in forum Import/Export Data
    Replies: 3
    Last Post: 08-31-2012, 08:00 AM
  3. Replies: 1
    Last Post: 08-23-2012, 08:32 AM
  4. Replies: 1
    Last Post: 08-09-2012, 08:21 AM
  5. Error Using "Browse To" Macro Command
    By Aaron5714 in forum Access
    Replies: 2
    Last Post: 06-14-2012, 03:01 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