dlookup based on field in form

S

s4

Hi,
This is really bugging me.
I have a form with [Closing], [Opening], [Month] and [PrevMonth] on it, all
linked into the same table. When I click a button, I want to copy the
[Closing] from the record in [PrevMonth]. This means if the [Month] is Aug I
put JUL in [PrevMonth] and click to copy JUL's Closing into Aug's Opening.
I'm using
Me.Opening_5 = DLookup("CLOSING_5", "MONTH_END", "Month ='" &
Me.PrevMonth.Value & "")


But it isn't working. Please help!
Thanks
 
O

Ofer Cohen

When you say it doesn't work, do you get an error? if so, what is the error?

If the value in PrevMonth is text, then the dlookup missing a closing single
quote:
Me.Opening_5 = DLookup("CLOSING_5", "MONTH_END", "[Month] ='" &
Me.PrevMonth.Value & "'")

If the value is numeric, then you need to remove the single quote from the
beginning
Me.Opening_5 = DLookup("CLOSING_5", "MONTH_END", "[Month] =" &
Me.PrevMonth.Value)

Is MONTH_END the name of the table or query
Is CLOSING_5 the name of the field in the table
When using key words in Access you need to put them in square brackets
(Month), it's not recommanded using KeyWords as fields name
 
S

s4

Thankyou a thousand times!!! It works!
Thanks.

Ofer Cohen said:
When you say it doesn't work, do you get an error? if so, what is the error?

If the value in PrevMonth is text, then the dlookup missing a closing single
quote:
Me.Opening_5 = DLookup("CLOSING_5", "MONTH_END", "[Month] ='" &
Me.PrevMonth.Value & "'")

If the value is numeric, then you need to remove the single quote from the
beginning
Me.Opening_5 = DLookup("CLOSING_5", "MONTH_END", "[Month] =" &
Me.PrevMonth.Value)

Is MONTH_END the name of the table or query
Is CLOSING_5 the name of the field in the table
When using key words in Access you need to put them in square brackets
(Month), it's not recommanded using KeyWords as fields name

--
Good Luck
BS"D


s4 said:
Hi,
This is really bugging me.
I have a form with [Closing], [Opening], [Month] and [PrevMonth] on it, all
linked into the same table. When I click a button, I want to copy the
[Closing] from the record in [PrevMonth]. This means if the [Month] is Aug I
put JUL in [PrevMonth] and click to copy JUL's Closing into Aug's Opening.
I'm using
Me.Opening_5 = DLookup("CLOSING_5", "MONTH_END", "Month ='" &
Me.PrevMonth.Value & "")


But it isn't working. Please help!
Thanks
 
Top