Results 1 to 8 of 8
  1. #1
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186

    Get data from a table to fill a variable on a module

    Hi everyone!



    I am creating a simple module where I want to get the data from a table (it has just one field and one record) in order to fill a variable from a module
    At the beginning I want to use Dlookup but it doesn't work, I don't know if the reason is that Dlookup needs a criteria

    My table is named [root_tbl] and the field is named [root] (it basically contains the root to record attached files for the app "C:\Users\name\Desktop\Foldername"

    This is my code... I highly appreciate ideas how to correct this...

    '*************************************************
    Function Ruta() As String


    'Create the root where all the documents attached will be sent

    'Ruta = "C:\Users\name\Desktop\Foldername"
    'The idea is to change the root directly from the table and not to get in to the module to change the code



    Ruta = DLookup("[Root]", "[root_tbl]")

    'I only want that the variable takes the unique information that it's contained on the field


    End Function
    '***************************************

    Thanks in advance!

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    If only one record, no need for criteria in DLookUp.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    Hi
    What would you recommend to change on my code?

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    Quote Originally Posted by charly.csh View Post
    Hi
    What would you recommend to change on my code?
    nothing. It should work.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    Please show a pic of your table root_tbl
    Data and structure

    Have you walked though the code?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Just as a side note, you can get that path without saving it in a table for each user:
    Code:
    Ruta = Environ("USERPROFILE") & "\Desktop\FolderName"
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Try it in the immediate window

    ? DLookup("Root", "root_tbl")

    You don't need the square brackets where there are no spaces in the field and table names.

    And tell us what the result or error is?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  8. #8
    charly.csh is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2014
    Posts
    186
    ohh I found the issue and it was into the root I had the "address" between " "
    after removing such it worked pretty good!

    Code was ok!

    Function Ruta() As String

    'Create the root where all the documents attached will be sent

    'Ruta = "C:\Users\name\Desktop\Foldername"
    'The idea is to change the root directly from the table and not to get in to the module to change the code


    Ruta = DLookup("[Root]", "[root_tbl]")

    'I only want that the variable takes the unique information that it's contained on the field

    End Function

    Thanks to everyone!!
    As well I reviewed the other alternatives you gave me and they works too, something new to add to my learning!!!!

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

Similar Threads

  1. Module level variable declaration.
    By bubai in forum Programming
    Replies: 33
    Last Post: 12-12-2020, 11:20 PM
  2. Getting Variable from Module to Report
    By dylcon in forum Modules
    Replies: 3
    Last Post: 02-14-2014, 03:43 PM
  3. Fill data entry textbox with variable
    By broecher in forum Forms
    Replies: 6
    Last Post: 11-18-2011, 07:54 PM
  4. Replies: 4
    Last Post: 05-16-2011, 04:58 PM
  5. Variable Table Names in a Module
    By Jessica in forum Modules
    Replies: 1
    Last Post: 04-19-2010, 07:38 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