Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    janjan_376 is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    14

    Dlookup


    I wanted to test how DLOOKUP works but I'm having a problem displaying the result into my textbox. I created a simple table with ID, FNAME, LNAME. I created a Form with a combobox name 'SenderIDCbo' and I am able to select the ID from the table.

    I put the following code in the AfterUpdate:

    dlookup("fname","senderTbl","text2='SenderIdCbo'")

    But I am not getting anything. Please help.

    Thank you.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,899
    See if this link helps a bit. Post back if it is still stubborn.
    (RG for short) aka Allan Bunch Previous MS Access MVP - WinXP Pro, Win7 Pro Win10 Pro - acXP, ac07, ac10, ac13
    How to mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  3. #3
    janjan_376 is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    14
    I typed in the following code according to the link you gave me but it's still not working

    dlookup("fname","senderTbl","text2= " & forms!Form1!senderidCbo)

    Please help. Thanks.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,899
    If [ID] is a numeric field then try:
    Me.Text2 = DLookup("[fname]","[senderTbl]","[ID]= " & Me.senderidCbo)
    ...and if a text field then try:
    Me.Text2 = DLookup("[fname]","[senderTbl]","[ID]= '" & Me.senderidCbo & "'")
    (RG for short) aka Allan Bunch Previous MS Access MVP - WinXP Pro, Win7 Pro Win10 Pro - acXP, ac07, ac10, ac13
    How to mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  5. #5
    janjan_376 is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    14
    Thanks for your respond. My ID or the name of the ID field is SenderID, is a numeric field, so I tried the one you suggested unfortunately my Text2 box is still not displaying anything. Do I have to do anything on the Table or relationship? This database has no query yet. I am just trying to create a very simple database which I can see the firstname of the ID I select in the Combo box. Thanks again. Please help.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,899
    Where do you have the code? Post the code starting with Private Sub...
    (RG for short) aka Allan Bunch Previous MS Access MVP - WinXP Pro, Win7 Pro Win10 Pro - acXP, ac07, ac10, ac13
    How to mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  7. #7
    janjan_376 is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    14
    Hi. I finally got it to work. Thanks a lot for your help and your patience. It did work perfectly. Good Job.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,899
    Glad to hear you got it working. Are you ready for the Solved thread tool yet?
    (RG for short) aka Allan Bunch Previous MS Access MVP - WinXP Pro, Win7 Pro Win10 Pro - acXP, ac07, ac10, ac13
    How to mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  9. #9
    janjan_376 is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    14
    I am not quiet ready yet for the Solved thread. I have another question relevant to this issue. I did make it work and tried to challenge myself by changing the ID to a mix of string and number. I change the format of the ID in my table into : \S000. Now everytime I input a new name that ID would says S001, S002....so on.

    I tried to change the code so it would accept text:

    Private Sub Combo0_AfterUpdate()
    Text2 = DLookup("fname", "senderTbl", "senderid= '" & Combo0 & "'")
    End Sub

    ERROR AFTER SELECTING THE ID ON THE FORM:

    "The value you have entered isn't valid for this field.
    For example you may have entered text in a numeric field or a number that is larger than the field size setting permits."


    This is my code that work with numeric ID:

    Private Sub Combo0_AfterUpdate()
    Text2 = DLookup("fname", "senderTbl", "senderid= " & Combo0)
    End Sub

    Please help again. Thank you.

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,899
    Changing the Output Format of a field in a table does not change the value stored in the field. It only changes how it looks when you display it.
    (RG for short) aka Allan Bunch Previous MS Access MVP - WinXP Pro, Win7 Pro Win10 Pro - acXP, ac07, ac10, ac13
    How to mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  11. #11
    janjan_376 is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    14
    I want to make it a little clearer. In the Table there is a General tab. Under that tab there is Field size, New Values, Format, and so on. In the Format box I put \S000 FOR ID (Autonumber). I believe this is causing the error because if I remove it and change the Dlookup line (in the form) to accept a numeric, it works.

    Please help. Thank you.

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,899
    If you leave the format string as is but change the DLookup() to use numeric, does it work?
    (RG for short) aka Allan Bunch Previous MS Access MVP - WinXP Pro, Win7 Pro Win10 Pro - acXP, ac07, ac10, ac13
    How to mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  13. #13
    janjan_376 is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    14
    No. It does not work. I am gettng error I mentioned previously.

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,899
    So with the format string in place you can not use numeric or string values in your DLookup(), right?
    (RG for short) aka Allan Bunch Previous MS Access MVP - WinXP Pro, Win7 Pro Win10 Pro - acXP, ac07, ac10, ac13
    How to mark the thread as Solved!
    Teaching is not filling a bucket but lighting a fire.
    Borrowed quote..."Docendo discimus"

  15. #15
    janjan_376 is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2009
    Posts
    14
    That's right. Please help.

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

Similar Threads

  1. # added to string with Dlookup
    By normever in forum Programming
    Replies: 1
    Last Post: 02-27-2009, 10:52 AM
  2. replacing dlookup fields with variables
    By msupitar in forum Access
    Replies: 0
    Last Post: 02-18-2009, 12:26 AM
  3. I have Problem in processing Dlookup Function
    By Katada in forum Programming
    Replies: 2
    Last Post: 04-23-2006, 12:07 AM
  4. Replies: 1
    Last Post: 01-10-2006, 12:32 PM
  5. Need Help for Dlookup function
    By wasim_sono in forum Programming
    Replies: 5
    Last Post: 01-04-2006, 08:18 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
  •  
Tech Forums: Microsoft Office Forums