K
Ken Snell [MVP]
It has arrived. I'll look at it later today.
--
Ken Snell
<MS ACCESS MVP>
--
Ken Snell
<MS ACCESS MVP>
Luke said:Got it. I just sent the db. More explanation in the email.
Thank you.
Luke
Ken Snell said:No, the database has not arrived yet, nor did the original one arrive.
I apologize that I cannot post the full email address here. I'll break it up
for you differently here. The email address can be obtained by putting the
following things together:
k
s n
e
l l
(the number nine)
the normal separator for email (that symbol!)
comcast
(the period)
the word short for network
--
Ken Snell
<MS ACCESS MVP>
(soLuke said:I have sent the db again this morning (both .mdb and .zip files). Let me
know if you have it (the subject is: Problem with Dlookup function from
Luke).
If not I must have not decipher the email correctly and will try something
else.
Thank you.
Luke
:
No, it has not arrived here yet.
--
Ken Snell
<MS ACCESS MVP>
Already sent it (an hour ago). Hopefully I got the email right
far(thenothing came back). Let me know if you have it.
Thank you again for your help.
:
As Bas notes, remove the words this is not real by removing those
letters,
in order, from the email address -- they are not embedded as the exact
words
in side-by-side letters.
If db is only 240K, then you don't need to zip the file.
--
Ken Snell
<MS ACCESS MVP>
Thank you for your offer.
However, how do I extract your email address? When I click on your
name I
can see your address, but do not know if it is .net or .com
cablesomethingcompany; right now is shows .renaetl) and your name or
else.canThe
db itself is only 240K. Should I still zip it?
Can you advise what to do next?
:
Yes, you may send me the database (zipped). My email address
bethe"extracted" from my post's reply email address by removing
wordsfindthis is
not real from the address.
Be sure to include specific information regarding how to
andbacktest
the
function, and what it's supposed to do vs. what it's doing.
I will take a look as time permits and then post a reply
hereerrorsin
the
newsgroup.
--
Ken Snell
<MS ACCESS MVP>
Hello Ken,
Good suggestion, but it still does not work. Technically, it
should,
but
somehow it does not. I get 222 and 444 to capture the
(13db Iand
94),
but no values.
If you would be interested I can send you example of the
usegetto
solve
this. Let me know if you can do that and if yes, how to
inistouch
with
you and how to send it (would zip be OK).
Thank you for your help. Greatly, greatly appreciate it.
:
I see a typo in the DLookup function's arguments. Here
what"tblForecast",you h
ave
posted:
dblFcstPct = DLookup("[FORECAST_GROWTH]",
_[FISC_MONTH]<="[PRODUCT_DESC]='" & strProduct & "'" & " And
[PRODUCT_ID]="
&
strProductID & _
" And '[PRODUCT_CODE]= & strProductCode '" & " And
[PLANT_LOCATION]=" & intLocation & _
" And [FISC_YEAR]=" & intYear & " And
" &argument.intMonth)
Note the line with the [PRODUCT_CODE] part of the
It"tblForecast",has
extraneous ' characters and is missing " characters. Try this
(watch
word
wrap by newsreader):
dblFcstPct = DLookup("[FORECAST_GROWTH]",
_""[PRODUCT_DESC]='" & strProduct & "'" & " And
[PRODUCT_ID]="
&
strProductID & _
" And [PRODUCT_CODE]='" & strProductCode & "'" &
And[FISC_MONTH]<=[PLANT_LOCATION]=" & intLocation & _
" And [FISC_YEAR]=" & intYear & " And
" &"tblForecast",intMonth)
Here is the above code step reformatted to fit in newsreader
window:
dblFcstPct = DLookup("[FORECAST_GROWTH]",
_The"[PRODUCT_DESC]='" & strProduct & "'" & _
" And [PRODUCT_ID]=" & strProductID & _
" And [PRODUCT_CODE]='" & strProductCode & _
"'" & " And [PLANT_LOCATION]=" & intLocation & _
" And [FISC_YEAR]=" & intYear & _
" And [FISC_MONTH]<= " & intMonth)
--
Ken Snell
<MS ACCESS MVP>
Function GetGrowthForecast(strProduct As String, strProductID
As
Integer,
_
strProductCode As String, intLocation As Integer, intYear
As
Integer,
_
intMonth As Integer) As Double
On Error GoTo ErrorHandler
'Find corresponding quota % based on all parameters entered
Dim dblFcstPct As Double
dblFcstPct = DLookup("[FORECAST_GROWTH]", "tblForecast", _
"[PRODUCT_DESC]='" & strProduct & "'" & " And
[PRODUCT_ID]=" &
strProductID & _
" And '[PRODUCT_CODE]= & strProductCode '" & " And
[PLANT_LOCATION]=" & intLocation & _
" And [FISC_YEAR]=" & intYear & " And [FISC_MONTH]<= "
&
intMonth)
If IsNull(dblFcstPct) = True Then
GetGrowthForecast = 0
Exit Function
ElseIf dblFcstPct = "" Then
GetGrowthForecast = 0
Exit Function
Else
GetGrowthForecast = dblFcstPct
End If
Exit_ErrorHandler:
On Error GoTo 0
Exit Function
ErrorHandler:
If err = 13 Then
GetGrowthForecast = 222
ElseIf err = 94 Then
GetGrowthForecast = 444
Else
MsgBox err.Number & " " & err.Description & " has
occured." &
vbCrLf
& _
"Please check the error."
Resume Exit_ErrorHandler
End If
End Function
This is the function and how it stands now.
There are two tables with different number of fields.
6notparameters
fields and the forecast field are the same:
The table that receives the value (with update query) is
tblProduction
(table that provides the values is tblForecast).
Following are the field names in table tblForeast with
tblProduction
names
in (), followed by Data Type and Detail:
PRODUCT_DESC (Product) Text 6
PRODUCT_ID (ProductID) Number Integer
PRODUCT_CODE (ProductCode) Text 2
PLANT_LOCATION (Location) Number Integer
FISC_YEAR (Year) Number Integer
FISC_MONTH (Month) Number Integer
FORECAST_GROWTH (GrowthForecast) Number Double
Let me know if you also need values. However, I can
postToothe
actual
values for confidentiality reasons. I may change the values
but
am
unsure
if
that would not change the overall scope and how the function
behaves,
but
I
will try (please specify format).
Thank you for your help.
:
Let's have you post the real code/table info/etc.
manycanerrors
creep
in
when you try to genericize the information.
Ken Snell
<MS ACCESS MVP>
Thank you for your suggestions:
The TableB is just a typo. There is no space in actual
function
(I am
substituting actual names with fictitious one; I
postofthe
function
with
actual names if preferable).
I have checked and I do not use any reserve words.
I have hardcoded the function (great idea!). I have
changed
the
first
parameter coding (I have repositioned ' in the function).
I have also found what possibly could be the cause
allonethe
problems
and
it's the last field: Month. The TableA has production
values
for
every
month; the forecast table (TableB) may have only
valueexamplefor
the
whole
year
or as many as 12 for each month. Here is an
for(thatTableB:
2 - 16%
5 - 13%
9 - 2.5%
What this means is that for period 2-4 forecast is 16%,
5-8
13%,
9-present
2.5% and I need to update this value to TableA
is(errorwhy
the
last
statement read<=). Since I do not have values for 3,4,6,
etc.
I
get
error
message in the function: Invalid use of Null
94).butI have IsNull and "" If statement to catch unmatched
values
(they
should
be
zero). However when I use If statement for IsNull=True, I
still
get
this
error. I can capture the error in ErrorHandler,
thisnamewill
not
give me
any value whatsoever.
What do I do?
:
You're using a name for the table of
TableB(space)
Try removing the space at the end of the table
inguessthe
second
argument
of the DLookup function.
If that doesn't fix the problem, then I would
thattheyour
criterias
are
not matching correctly, even though you say the
variables
have
the
right
values.
Try "hardcoding" values into the DLookup function
(values
that
you
know
are
in the table) to see if the DLookup then works. Watch
out
for
differences in
data types for fields versus the data type of
valuesforthat
you're
using.
If this doesn't work, you'll need to post info
ussampleregarding
how
the
table's fields are designed/formatted, some
datanotfor
the
table's
fields and the variables.
Also, it appears that your table's fields are using
reserved
words,
which
can cause great confusion in ACCESS. See this Knowledge
Base
article
for
more information:
ACC2002: Reserved Words in Microsoft Access
http://support.microsoft.com/default.aspx?scid=kb;en-us;286335
--
Ken Snell
<MS ACCESS MVP>
Thanks for the suggestion, Nikos, but it did
work."TableBOriginally
I
had
it
as you write, but I streamlined it. Still get 77.
:
Luke,
Syntax errors in the DLookup. Try:
dblQuota = DLookup("[GrowthQuotaFcst]",
", _[Month]<="[Product]= '" & Filed1 & "' And [ProductID]= "
&
Filed2 &
_
" And [Location]= '" & Filed3 & "' And
[Division]=
" &
Filed4 &
_
" And [Year]= " & Filed5 & " And
" &Filed2Filed6 )
HTH,
Nikos
Luke wrote:
Function UpdateQuota(Filed1 As String,
As[ProductID]=Integer,
Filed3
As
String, _
Filed4 As Integer, Filed5 As Integer, Filed6
As
Integer)
As
Double
Dim dblQuota As Double
dblQuota = DLookup("[GrowthQuotaFcst]",
"TableB ",
_
"'[Product]= Filed1 ' And
" &supposedFiled2
& _
" And '[Location]= Filed3 ' And
[Division]= "
&
Filed4
& _
" And [Year]= " & Filed5 & " And [Month]<=
" &
Filed6)
If IsNull(dblQuota) = True Then
UpdateQuota = 33
ElseIf dblQuota = "" Then
UpdateQuota = 77
Else
UpdateQuota = dblQuota
End If
End Function
I have created this function. It is
togoodupdate
Production
table
(Table A) with Production Forecast values (Table
B).
I
can't
create a
query
linking these 2 tables (Table A & B) since some of
the
values
last
for
more
then a month and sometimes the value is
for athatyear
and as
such, I
use an
Update query based on Table A and this function.
However, when I run this function I get 77, or
empty,
not
null
value
(I set
up the If statement intentionally to know what
result
I
get;
when
this
function works properly both 33 and 77 will be
replaced
with
zero).
When I
place a break in the function, all the variables
show
correct
value,
but the
result is still blank. I have verified
bothsuggestionstables
have
the
6
values
needed to identify the GrowthQuotaFcst.
I am at the end of my wits. Any
onwhat
to do
next,
what
am I
doing wrong? Is there a limit on how many
conditions
(in
this
case 6)
DLookup function can have? Or maybe I should
change
all
this
and
use
Loop
statement? Or something else?
I greatly appreciate your help.