+ Reply to Thread
Results 1 to 6 of 6

Thread: Auto Populate from a Search Query

  1. #1
    Registered User
    Join Date
    05-24-2010
    Location
    Rockville, MD
    MS-Off Ver
    Excel 2007
    Posts
    47

    Auto Populate from a Search Query

    Hello,

    I have 2 tables: 1) tbl - Issue_Codes and 2) tbl - Master Table

    Step1 - I created a Search query using the "Loan Number" field in "Master Table". I named this query"qry - Loan Information Search."

    Step 2 - I then created a form using this Search query. However, the "Issue_ID" field in this form was unable to give me the drop down box, so I deleted and add the existing fields (Issue_ID and Issue_type) from the Master Table itself. Now, I have a Search form with "Issue_ID" field having the drop down box.

    Step 3 - Create an auto populate field (Issue_type) in the form. This is where I'm stuck and need help! I want to select the "Issue_ID" in the drop down box and the "Issue_type" field will auto populate based on the references in "Issue_Codes" table. How can I write a DLookUp in "Issue_type" Control Source? Please Help! Thank you so much!

    Hmm. Can't seem to attach my dummy db zip file! The file is only 2.4 MB! What should I do here?

    LH
    Last edited by Dhoang25; 06-23-2011 at 02:23 PM.

  2. #2
    Forum Guru davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2007
    Posts
    1,879

    Re: Auto Populate from a Search Query

    I think rather than using the Control Source property in the form design view, you need to use the Issue_ID dropdown change event. Then you can set the source based on the value in your Issue_ID dropdown using vba.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Registered User
    Join Date
    05-24-2010
    Location
    Rockville, MD
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: Auto Populate from a Search Query

    Davegugg,

    So I should go to "On Change" in Event property and enter a VBA code? Can I get the VBA code since I'm still new at this? Thanks a bunch!


    LH

  4. #4
    Registered User
    Join Date
    05-24-2010
    Location
    Rockville, MD
    MS-Off Ver
    Excel 2007
    Posts
    47

    Re: Auto Populate from a Search Query

    Thanks Dave! I made the changes in Event property and it works! Here is the VBA code that I used. Thanks!

    Private Sub Issue_ID_Change()
    Issue_type.Value = DLookup("Issue_type", "tbl - Issue_Codes", "Issue_ID ='" & Me.Issue_ID.Value & "'")
    Me.Form.Refresh
    End Sub

    *Note - the '" above is apostrophe then quotation and "'" is quotation, apostrophe, quotation.

  5. #5
    Forum Guru davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2007
    Posts
    1,879

    Re: Auto Populate from a Search Query

    Actually, I'd use the After Update event. Then you'd want something like this:

    Forms("Your_Form_Name").Issue_Type_Control.RowSource = "SELECT IssueType FROM Master_Table WHERE Issue_ID = " & Forms("Your_Form_Name").Issue_ID_Control.Value
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  6. #6
    Forum Guru davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2007
    Posts
    1,879

    Re: Auto Populate from a Search Query

    Oops, I see I just missed you. You can use a DLookup to return one record, but if you want to return more than one record, like for a listbox, you would want to use a sql statement like my example in post 5.

    Glad you were able to get it!
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0