Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2014
    Posts
    7

    Question Unanswered: Auto fill table based on another field

    I have a table titled Koper. There are two fields in it called: Buyer and Address. I have another table titled Main to which the records are saved to. The two fields in question are; Buyer and Address. I have a form titled FrmMain with two comboboxes for the Buyer (cmbBuy) and Address (cmbAddress).

    When I choose the correct Buyer on the form I want the Address field to be filled automatically.

    After research on the i/net I found and adjusted the following code to be entered in the AfterUpdate of cmbBuy. It does not word and the debugger tell met the syntax is wrong - I can't locate the problem;

    Code:
    Dlookup("[Address]", "[Koper]", "[Koper].[Buyer] = """ & Me!cmbBuy & """")

    Thanks

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    what datatype is Buyer?
    if string then the value must be delimited with a pair of " or '. in thsi case you are probably better of using the ' to delimit within the VBA string
    Code:
    Dlookup("[Address]", "[Koper]", "[Koper].[Buyer] = '" & Me!cmbBuy & "'")
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Oct 2014
    Posts
    7

    Auto fill table based on another field

    Thanks for your reply. I copied and paste your suggestion but now get the compile error "Expected; ="

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    What are you assigning the value of the dlookup to?
    Eg
    mycontrol.text = dlookup.......
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Oct 2014
    Posts
    7

    Auto fill table based on another field

    Firstly; the field type for both Buyer and Address is Text.

    I am new to Databases and do not understand your question: "What are you assigning the value of the dlookup to?
    Eg
    mycontrol.text = dlookup......."

    I did the following;
    I entered the code on the Form (FrmMain) in the AfterUpdate of cmbBuy to fill cmbAddress.

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Dlookup returns a value which should be assigned to a variable or a control. The error message is suggesting you are not doing that
    what you probably need is

    Cmbaddress.text = dlookup......
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Oct 2014
    Posts
    7

    Auto fill table based on another field

    Sorry to be such a pain in the neck, but seems that I cannot get it to work.
    I entered the following code;
    cmbAddress.Text = DLookup("[Address]", "[Koper]", "[Koper].[Buyer] = ' " & Me!cmbBuy & " ' ")
    Now I get a message "Microsoft Access can't find the filed 'cmbBuy' in your expression - Runtime Error 2465

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
  •