Solved

Dlookup help

Posted on 2008-09-29
6
258 Views
Last Modified: 2013-11-28
I am using this code to autopopulate fields in the form. the fields get the information from a seperate table to the main table. but when using this code in the after update i get an error message. runtime error "2766", The object does not contain the automation object "blah blah blah". but when i had the code
Me.Pattern_.Value = DLookup("[PatternCode]", "Pattern",  Me.Style_.Value) it worked but would always bring up the first entry in the patterm table.
Private Sub Style__AfterUpdate()

Dim PDMDate As Variant

Dim appDate As Variant
 

Me.Pattern_.Value = DLookup("[PatternCode]", "Pattern", "Style_=" & Me.Style_.Value)

PDMDate = DLookup("[DateApproved]", "Pattern", Me.Style_)

appDate = DLookup("[PDMReceived]", "Pattern", Me.Style_)
 

Me.PDM_Date.Value = PDMDate

Me.Approval_Date.Value = appDate

End Sub

Open in new window

0
Comment
Question by:onaled777
  • 3
  • 3
6 Comments
 
LVL 84
ID: 22603639
Is "Style_" the actual name of your field?

Try removing the square brackets ... they're not needed.

Is "Style_" a text or numeric value? If it's Text, you'll need to enclose it in quotes:

Me.Pattern_.Value = DLookup("PatternCode", "Pattern", "Style_='" & Me.Style_.Value & "'")

And if "Style_" IS the actual name of you field/control, then I'd strong suggest you look into nameing conventions for your objects ...

0
 

Author Comment

by:onaled777
ID: 22604098
Thanks for your responce. The code now works but I am back to the same problem were the code is now always bring up the first entry in the patterm table. The Name of the field control is Style#. I have other code that works with the style# name of the control on the form. Just can't seem to get this Dlookup working. Thanks again for your help.
0
 
LVL 84
ID: 22604894
Well, if "style #" is the actual name of your control, then you'd refer to it as such:

Me.Pattern_.Value = DLookup("PatternCode", "Pattern", "[Style #]='" & Me.[Style #].Value & "'")

And please - look into those nameing conventions. The hash mark ( # ) is used in Access to delimit dates, and should never be used in a control or field name.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:onaled777
ID: 22606377
I cant understand what is going on. I change to code to match your suggestion and get a erroe. So I decided to go in and change my field names to more convetional names. When i did that the look is pulling up the first value in the pattern table again. I will zip file and attach it to this question. This code is the last thing I need to get working to deliver this DB. Any help would be greatly appriciated.
Dwayne-Project-Version-1.6--9-23.zip
0
 

Author Comment

by:onaled777
ID: 22614622
I came up with the answer. There was noting really wrong with the syntax of the Dlookup. It was all in the way I was naming the fields in my tables. When I renamed fields as suggested The Dlookup worked. I no know that u need to pay extra special attention to table design and naming conventions
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 22762069
Generally if a comment by one of the Experts led you to your answer you would accept that as the answer. You might look into the grading guidelines in the Help file for more assistance.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now