Automatically populate a field from combo box


A

AceWill

I'm trying to use some code in the after update event on a combo box in a
form. I'm trying to select "Reason Denied"(from 1 table) in a combo box and
based on that selection have it automatically populate "Statement for
Letter"(from another table. I'm not very good with code so I am looking for
a solution to why the following code isn't working.

Private Sub Reason_Denied_AfterUpdate()
Me.[Statement for Letter].Value = DLookup("[Statement for Letter]",
"[Reason Denied]", _
"[Statement for Letter] =" & Me.[Reason Denied].Value)
End Sub

Thanks,
Chad
 
Ad

Advertisements

A

AceWill

I watched a couple of video tutorials and still can't get this to work. Here
is my new code for the after update event in the combo box.

Private Sub ReasonDenied_AfterUpdate()

StatementforLetter = DLookup("StatementforLetter", "ReasonDenied",
"ReasonDenied=" & ReasonDenied)

End Sub

Table (Penalty Waivers)
column 1(address)format text, column 2(city, state, zip)format text, column
3(ReasonDenied)format text, column 4(StatementforLetter)format memo.

Table (ReasonDenied)
column 1(ReasonDenied)format text & primary key,
column2(StatementforLetter)format memo

I have a form based on the Penalty Waivers table with a combo box for
"ReasonDenied". I want the "StatementforLetter" field to be populated when i
select the "ReasonDenied" from the combo box. I can't get it to work,
hopefully someone can help and I hope you can understand what I am saying.

Thanks,
Chad


bhicks11 via AccessMonster.com said:
Hi Chad,

Where is the reference to the combobox? Why is [Statement for Letter] in the
DLookup twice? You don't have to use .Value in that line. You may need to
refer to the column in the combobox. So if the combobox is MYCOMBOBOX you
would use:

me.mycombobox.column(0)

(starts at zero). Make sure your DLOOKUP is correct. I can't tell because I
don't know what your table structures are.

DLOOKUP - 1. what field you want to return from a given table - 2. What
table you want to get it from - 3. the criteria

Bonnie
http://www.dataplus-svc.com
I'm trying to use some code in the after update event on a combo box in a
form. I'm trying to select "Reason Denied"(from 1 table) in a combo box and
based on that selection have it automatically populate "Statement for
Letter"(from another table. I'm not very good with code so I am looking for
a solution to why the following code isn't working.

Private Sub Reason_Denied_AfterUpdate()
Me.[Statement for Letter].Value = DLookup("[Statement for Letter]",
"[Reason Denied]", _
"[Statement for Letter] =" & Me.[Reason Denied].Value)
End Sub

Thanks,
Chad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top