Results 1 to 3 of 3
  1. #1
    Joakim N is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Oct 2016
    Posts
    79

    Use Function in VBA

    Hi,

    I have used function DLookUp as ControlSource to a TextBox in a Form according to:



    =DLookUp("[Company]";"[TCompany]";"[ID_Company]=1")

    How can I write the same function but I want to store it to a variable in VBA? (In VBA Excel I use WorksheetFunction. to use a built in function) I don't know how to use a built in function in VBA Access.

    Code:
    Dim sCompany As String
    
    'This line doesn't work. Of Course. But how can I write this code?
    sCompany=DLookUp("[Company]";"[TCompany]";"[ID_Company]=1")

  2. #2
    Joakim N is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Oct 2016
    Posts
    79
    I found it myself. I just had to replace my ";" to ","

    Code:
    Dim sCompany As String
    sCompany = DLookup("[Company]", "[TCompany]", "[ID_Company]=1")

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    just to clarify - regional settings can make a difference. You are using semi colons as parameter separators - they are usually commas

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

Similar Threads

  1. Replies: 3
    Last Post: 03-04-2016, 10:36 AM
  2. Replies: 8
    Last Post: 11-04-2014, 10:44 PM
  3. Replies: 8
    Last Post: 01-31-2014, 01:45 PM
  4. Iif function
    By Bertrand82 in forum Access
    Replies: 2
    Last Post: 02-04-2013, 05:58 AM
  5. Want function to get current function name
    By Davis DeBard in forum Programming
    Replies: 2
    Last Post: 08-13-2009, 05:02 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