DLookup issue (1 Viewer)

kryten

Registered User.
Local time
Today, 04:12
Joined
Jul 24, 2004
Messages
40
Hi everyone,

I have a subform [frmOrderDetailsSubform] on which I am trying to use DLookup as the controlsource for a field to look up the [OnHand] field in my query [qryOnHand2].

=DLookUp("[OnHand]","[qryOnHand2]","
Code:
 = Forms![frmOrderDetailsSubform]![Code]")

This works fine when I open the subform as a standalone, however when I open the subform as part of the main form I get a flickering #Error.

Any advice would be greatly appreciated.
 

KenHigg

Registered User
Local time
Today, 07:12
Joined
Jun 9, 2004
Messages
13,327
If code = number:

=DLookUp("[OnHand]","[qryOnHand2]","
Code:
 = " & Forms![frmOrderDetailsSubform].form![Code])

or If code = string:

=DLookUp("[OnHand]","[qryOnHand2]","[Code] = '" & Forms![frmOrderDetailsSubform].form![Code] & "'")


???
kh
 

kryten

Registered User.
Local time
Today, 04:12
Joined
Jul 24, 2004
Messages
40
Hi Ken,

Thanks for your reply.


This works only when I open the subform as a standalone. When it is opened as part of the main form I get #Name?

Any other advice you could give would be appreciated.
 

KenHigg

Registered User
Local time
Today, 07:12
Joined
Jun 9, 2004
Messages
13,327
My Bad. Try:

=DLookUp("[OnHand]","[qryOnHand2]","
Code:
 = " & Forms!myMainformName![frmOrderDetailsSubform].form![Code])

Substituting myMainformName with the main form name...

???
kh
 

kryten

Registered User.
Local time
Today, 04:12
Joined
Jul 24, 2004
Messages
40
Hi Ken,

Tried that, this time I get #Name? when I open it as a standalone as well as on the main form.

Thanks for trying.
 

KenHigg

Registered User
Local time
Today, 07:12
Joined
Jun 9, 2004
Messages
13,327
Let's see; You have a main form with a subform that has a text box and you want to look up an on hand qty using dlookup and place this 'on hand qty' in the text box. Once you get this on hand qty in the text box, do you want to store it in the subform's underlying record source table or just view it?

???
kh
 

KenHigg

Registered User
Local time
Today, 07:12
Joined
Jun 9, 2004
Messages
13,327
You must have something named wrong...

Can you put enough of this in a post?

kh
 

kryten

Registered User.
Local time
Today, 04:12
Joined
Jul 24, 2004
Messages
40
I have pasted the relevant forms etc into a new database and attatched it ( the whole database is too big)
 

Attachments

  • db5.zip
    78.4 KB · Views: 92

KenHigg

Registered User
Local time
Today, 07:12
Joined
Jun 9, 2004
Messages
13,327
=DLookUp("[OnHand]","[OnHand2]","
Code:
 = " & [Forms]![Orders3]![OrderDetails].[Form]![Code])


I didn't see a table or query called OnHand2. I assume you forgot to post it?


kh
 

kryten

Registered User.
Local time
Today, 04:12
Joined
Jul 24, 2004
Messages
40
Sorry Ken here it is again
 

Attachments

  • db5.zip
    56.4 KB · Views: 101

KenHigg

Registered User
Local time
Today, 07:12
Joined
Jun 9, 2004
Messages
13,327
OnHand2 is looking for OnHandQry and can't find it...

:)
 

kryten

Registered User.
Local time
Today, 04:12
Joined
Jul 24, 2004
Messages
40
OnHand2 is based on OnHandQry which is in turn based on several other queries (gets complicated!)

I don't understand why the DLookup works when you open the subform on it's own but not when it is part of the main form?

Thanks for your help
 

KenHigg

Registered User
Local time
Today, 07:12
Joined
Jun 9, 2004
Messages
13,327
Oh....

I see the problem. You can't do this with the control source when the form is in continuous forms view. And I don't think you can do it in the underlying query as it will make it an un-updatable query...

All you want to see is the qty on hand as you enter the details...

Hum... One last shot:

=DLookUp("[OnHand]","[OnHand2]","
Code:
 = " & me![Code])

kh
 

kryten

Registered User.
Local time
Today, 04:12
Joined
Jul 24, 2004
Messages
40
No joy - still get #Name?

Isn't there any other way to reference it than using DLookup?

Thanks for trying
 

KenHigg

Registered User
Local time
Today, 07:12
Joined
Jun 9, 2004
Messages
13,327
Hum. Check this out:

kh
 

Attachments

  • dbtest_001.zip
    14 KB · Views: 92

kryten

Registered User.
Local time
Today, 04:12
Joined
Jul 24, 2004
Messages
40
I couldn't open this file - unrecognised database format (I'm using Access 97)
 

KenHigg

Registered User
Local time
Today, 07:12
Joined
Jun 9, 2004
Messages
13,327
Oh well. I got dlookup to work in a sub form...

I wonder if anyone else in the forum can convert this for you...

kh
 

KenHigg

Registered User
Local time
Today, 07:12
Joined
Jun 9, 2004
Messages
13,327
This was the line:

=DLookUp("[name]","tblColors","
Code:
 = '" & Forms!form2!form1.Form!colorcode & "'")

kh
 
Local time
Today, 06:12
Joined
Aug 2, 2004
Messages
6
I thought I'd take a shot at this and the code that I wrote should work except that your query OnHand2 is trying to get its information from a query called OnHandQry and this query doesn't seem to exist. The following code will access the information if you can figure out where that query went or redesign OnHand2 to gather it's data from another source and edit the code accordingly.

I just put this sode in the Form Load event for the subform. I hope this helps.
Joe :cool:

Private Sub Form_Load()
Dim SomeVariable As String

SomeVariable = DLookup("[OnHand]", "OnHand2", "
Code:
 = Forms!Orders3![OrderDetailSubform]!Form![code]")
OnHand.Value = SomeVariable

End Sub
 

Users who are viewing this thread

Top Bottom