Solved

Dlookup help

Posted on 2008-09-29
6
268 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

911 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

18 Experts available now in Live!

Get 1:1 Help Now