Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    vfares is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2020
    Posts
    6

    Post DLookup issue

    Hello,
    Table Name: tblDAO
    Form Name: Task Details
    Inside the form, i have a ComboBox & TextBox
    ComboBox Name: cb_DAO_Task
    TextBox Name: tb_DAODesc_Task
    I added the following code on the AfterUpdate event:

    Me.tb_DAODesc_Task = DLookup("DAODescription", ”tblDAO”, "DAO=" & Me.cb_DAO_task)

    The reason is that i want to bring from the table (tblDAO) a value that match what I chose in the ComboBox to place it in the TextBox

    the issue is that i am receiving error 2428 and other errors without knowing the reson.
    Can you help me?

    NB. i tried the following code also and having the same problem:

    Me.tb_DAODesc_Task = DLookup("[DAODescription]", ”tblDAO”, "[DAO]=" & Me.cb_DAO_task)

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Why not include data in a hidden column of the comb and then use something like:

    = [cb_DAO_task].Column(2)

    as the Control Source of the text box.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    I'd hesitate to use DAO as a field name although I dont think it is specifically a reserved word.
    Bob's suggestion is probably the way to go.

    what is the value of Me.cb_DAO_task? is it text or numeric?
    If text it needs to be delimited.

  4. #4
    vfares is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2020
    Posts
    6
    Helloo,
    Thank you for your reply.
    Me.cb_DAO_task is number not text.
    What do u mean by delimited.
    As for DAO field, can you please let me know why isn't recommended?
    I am a beginner in coding, thank you for your assistance.

  5. #5
    vfares is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2020
    Posts
    6
    Thank you Bob for your reply.
    I will try your suggestion.
    But what do u think the issue is in the initial code?

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    What is the data type of field DAO

    What happens if you change the name of that field
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    CarlettoFed is online now Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    255
    Perhaps by attaching a sample file it is easier to understand what accsde is and thus advise you.

  8. #8
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Quote Originally Posted by CarlettoFed View Post
    Perhaps by attaching a sample file it is easier to understand what accsde is and thus advise you.
    which post refers to "accsde". I can't see it
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  9. #9
    vfares is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2020
    Posts
    6
    DAO field type is Short Text

  10. #10
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Quote Originally Posted by vfares View Post
    Thank you Bob for your reply.
    I will try your suggestion.
    But what do u think the issue is in the initial code?
    I think the issue is that you need delimiters (') around the data used in the criteria.
    Try:

    Me.tb_DAODesc_Task = DLookup("[DAODescription]", ”tblDAO”, "[DAO]='" & Me.cb_DAO_task & "'")
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  11. #11
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    @vfares

    Can you show us the SQL statement used as the Row Source property of the combo box called "cb_DAO_task"
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  12. #12
    vfares is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2020
    Posts
    6
    Hello @Bob,
    i tried this: Me.tb_DAODesc_Task = DLookup("[DAODescription]", ”tblDAO”, "[DAO]='" & Me.cb_DAO_task & "'")
    and this:
    = [cb_DAO_task].Column(2)
    NO SUCCESS
    i attached the file, can you help me to find the issue?
    Attached Files Attached Files

  13. #13
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    SUCCESS

    1) I would still favour the method I suggested in post #2

    2) In the attached db I have made some changes to the combo box so that it is now configured in what, IMHO, I consider to be the proper/usual way. See the attached db. (this was not the problem)


    3) At first I couldn't see anything wrong with the DLookup() syntax but then I realized that the quote marks (") each end of tblDAO were different from all the others in the expression.
    I can't imagine where you got them from but replacing them allowed the expression to work.
    Attached Files Attached Files
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  14. #14
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    Note that a combobox rowsource is zero based. That means that the first column is refered to as .Column(0). the second column is .column(1) and the third is .column(2) and so on.
    try the afterupdate of the combobox with
    Code:
    Private Sub cb_DAO_task_AfterUpdate()
    
    
        Me.tb_DAODesc_Task = Me.cb_DAO_task.Column(1)
    
    
    End Sub

  15. #15
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    Quote Originally Posted by vfares View Post
    Helloo,
    As for DAO field, can you please let me know why isn't recommended?
    I am a beginner in coding, thank you for your assistance.
    DAO is a reference to Data Access Objects. You'll often see, for instance, "Dim Db as DAO.Database"
    There are many words that are considered reserved words. Using them as field names may cause errors or unexpected results.
    For instance Date, Day, Month are reserved words. see this link for a list . . . http://allenbrowne.com/AppIssueBadWord.html

    While DAO is not listed, I tend to avoid anything that could even possibly cause a problem.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Dlookup issue
    By onlylonely in forum Programming
    Replies: 2
    Last Post: 03-13-2020, 02:39 AM
  2. Dlookup issue
    By AccessRockie in forum Access
    Replies: 5
    Last Post: 11-27-2019, 08:03 AM
  3. Issue with DLookup
    By NewProgramPerson in forum Forms
    Replies: 12
    Last Post: 11-04-2019, 07:24 PM
  4. dlookup issue
    By Gina Maylone in forum Access
    Replies: 2
    Last Post: 05-09-2017, 11:36 AM
  5. Dlookup issue
    By Gilgamesh in forum Forms
    Replies: 5
    Last Post: 12-22-2012, 10:26 PM

Tags for this Thread

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