DLast for a Sub Form (1 Viewer)

wizcow

Registered User.
Local time
Today, 08:36
Joined
Sep 22, 2001
Messages
236
Hi

My Inventory form has StockTakeDate and IDNumber.
The InventorySub form has the Parts data including Quantity.

On another form I am trying to use a DLookUp function to look up the part's last Invnetory date.

=DLast("[StockTakeDate]","[Inventory]","Form.[ItemNo]=[ItemNo]")

This doesn't work, probably because it does not reference the Sub Form.

How can I re-write this to make it work?

Tom
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:36
Joined
Feb 19, 2002
Messages
43,199
For one thing, you need to use DMax() since you want the most recent date (the date with the highest value). DLast() would return the record positionally last in the recordset which might be the first date, the last date, or more likely something in between. Then you need to refer to a form field correctly:

=DMax("[StockTakeDate]","[Inventory]","[ItemNo] = Forms!YourFormName!YourSubformName.Form![ItemNo])
 

wizcow

Registered User.
Local time
Today, 08:36
Joined
Sep 22, 2001
Messages
236
Pat Hartman

I gave this a try;

=DMax("[StockTakeDate]","[Inventory]",[ItemNo] =Forms!Inventory!InventorySub.Form![ItemNo]")

and I get an #Error cycling in the text box.

I'm stuck!

Tom
 

Fornatian

Dim Person
Local time
Today, 15:36
Joined
Sep 1, 2000
Messages
1,396
type error caused that error, try:

=DMax("[StockTakeDate]","[Inventory]","[ItemNo] =" & Forms!Inventory!InventorySub.Form![ItemNo])
 

wizcow

Registered User.
Local time
Today, 08:36
Joined
Sep 22, 2001
Messages
236
Ian

Now I get this error

#Name?

Spelling is correct. I tried a short version;

=DMax("[StockTakeDate]","[Inventory]","[ItemNo] = [ItemNo]")

This produces a date (the wrong date, but the naming convention is correct)

Tom
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:36
Joined
Feb 19, 2002
Messages
43,199
The syntax posted by Fornatian is correct if ItemNo is numeric. If ItemNo is text, you'll need to enclose the value in quotes.

=DMax("[StockTakeDate]","[Inventory]","[ItemNo] ='" & Forms!Inventory!InventorySub.Form![ItemNo] & "'")
 

wizcow

Registered User.
Local time
Today, 08:36
Joined
Sep 22, 2001
Messages
236
I thought using a DLookUp was going to be easy!


The [ItemNo] in the Parts table is an 'AutoNumber'
The [ItemNo] in the InventorySub table is a 'Number'

Will this make a difference?

Tom
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:36
Joined
Feb 19, 2002
Messages
43,199
The syntax is correct so that leaves the form reference suspect. Open the main form in design view. Click on the subform and open its properties dialog. Make sure that "Name" on the "Other" tab = "InventorySub". If it does not, change the subform name in the DLookup() so that it matches the actual one.
 

Users who are viewing this thread

Top Bottom