473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Using DLookup for different customer types and treatment

129 100+
Hi can anybody help me with this problem?

I have a customer order form with a sales order line subform. The subform contains products ordered by customers, each (wooden) product can come in two different treatment types; golden brown or pressure treated of which are of two different prices. The prices are also determined by the customer type; pub, garden centre or public.

Currenlty on the treatment combo box, i have a dlookup in the code builder which looks up the price for the product dependant on whether GB (golden brown) or PT (pressure treated) is selected, this works fine for customer types pub (1) and garden centres (2) as the dlookup looks up the customertype and treatment type in a customertypeprice table, and then displays the price in the unit price field on the subform, however for the public customer type, no prices are set in the customertypeprice table as these need to be manually entered in.
I need to able to put this somewhere within the following code,something like 'if customer type = 3 (public) then set focus to the unit price field to allow me to enter a manual price. Does anybody have any ideas on how i can do this? The customer type field isnt within the subform but stored on the main form (frmcustomer3). Currently when i select customer type 3 on the main form and i select the treatment combo box an error occurs because the dlookup cant find customertype 3 in the customertypeprice table.

Here is my current code:
Expand|Select|Wrap|Line Numbers
  1. Dim strFilter As String
  2.  
  3. strFilter = "ProductID = " & Me.ProductID & " And CustomerTypeID = " & Forms![frmCustomer3]![CustomerTypeID]
  4.  
  5.     If Treatment.Value = "GB" Then
  6.         Me.SOUnitPrice.Value = DLookup("[GoldenBrownUnitPrice]", "tblCustomerTypePrice", strFilter)
  7.     ElseIf Treatment.Value = "PT" Then
  8.         Me.SOUnitPrice.Value = DLookup("[PressureTreatedUnitPrice]", "tblCustomerTypePrice", strFilter)
  9.  
  10.     End If
Any suggestions would be great because ive been trying to do this for weeks!
Mar 30 '08 #1
3 2275
PianoMan64
374 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. Dim strFilter As String
  2.  
  3. strFilter = "ProductID = " & Me.ProductID & " And CustomerTypeID = " & Forms![frmCustomer3]![CustomerTypeID]
  4.  
  5. If Treatment.Value = "GB" Then
  6. Me.SOUnitPrice.Value = DLookup("[GoldenBrownUnitPrice]", "tblCustomerTypePrice", strFilter)
  7. ElseIf Treatment.Value = "PT" Then
  8. Me.SOUnitPrice.Value = DLookup("[PressureTreatedUnitPrice]", "tblCustomerTypePrice", strFilter)
  9. End If
  10. If Forms![frmCustomer3]![CustomerTypeID] = 3 Then
  11. docmd.Gotocontrol "frmCustomer3"
  12. docmd.gotocontrol "UnitPrice" 'Name of the control that you want to change. 
  13. End if
  14.  
  15.  
Apr 1 '08 #2
Constantine AI
129 100+
Hi, thank you for your reply, I changed my code to the following but i keep getting an error message of 'Run-Time error 2108' You must save the field before you execute the GoToControl action, the GoToControl method or SetFocus method

this error message highlights the line DoCmd.GoToControl "SOUnitPrice"

Do you have any ideas to why this is or what i can do?

Dim strFilter As String

strFilter = "ProductID = " & Me.ProductID & " And CustomerTypeID = " & Forms![frmCustomer3]![CustomerTypeID]

If Forms![frmCustomer3]![CustomerTypeID] = 3 Then
DoCmd.GoToControl "sfrmSOLine3"
DoCmd.GoToControl "SOUnitPrice"
End If

If Treatment.Value = "GB" Then
Me.SOUnitPrice.Value = DLookup("[GoldenBrownUnitPrice]", "tblCustomerTypePrice", strFilter)
ElseIf Treatment.Value = "PT" Then
Me.SOUnitPrice.Value = DLookup("[PressureTreatedUnitPrice]", "tblCustomerTypePrice", strFilter)
End If

End Sub
Apr 2 '08 #3
PianoMan64
374 Expert 256MB
Hi, thank you for your reply, I changed my code to the following but i keep getting an error message of 'Run-Time error 2108' You must save the field before you execute the GoToControl action, the GoToControl method or SetFocus method

this error message highlights the line DoCmd.GoToControl "SOUnitPrice"

Do you have any ideas to why this is or what i can do?

Dim strFilter As String

strFilter = "ProductID = " & Me.ProductID & " And CustomerTypeID = " & Forms![frmCustomer3]![CustomerTypeID]

If Forms![frmCustomer3]![CustomerTypeID] = 3 Then
DoCmd.GoToControl "sfrmSOLine3"
DoCmd.GoToControl "SOUnitPrice"
End If

If Treatment.Value = "GB" Then
Me.SOUnitPrice.Value = DLookup("[GoldenBrownUnitPrice]", "tblCustomerTypePrice", strFilter)
ElseIf Treatment.Value = "PT" Then
Me.SOUnitPrice.Value = DLookup("[PressureTreatedUnitPrice]", "tblCustomerTypePrice", strFilter)
End If

End Sub
So you have the The control CustomerTypeID Bound to a Field in a table?

Then you need to save the record before you move to the subform.

insert a:

Expand|Select|Wrap|Line Numbers
  1.  
  2. DoCmd.RunCommand acCmdSaveRecord
  3.  
  4.  
where you normally lose focus of the main form and get focus to the subform.

This will save the record.

But also you need to give me a brief layout of what the main screen looks like and what is bound on the main form and what is bound on the subform?

It may also be that you have some relationship issues that need to be resolved before we can even save the record depending on how the CustomerTypeID is selected?

Let me know.

Joe P.
Apr 3 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Eddy C | last post by:
Hi, I'm trying to get the value of another node using the position of another node or the name of the tag. Such that the current node is one of the contacts child nodes sec or prim and doing...
5
by: Kalvin Schroder | last post by:
I am fairly new to Access, and am trying to put together an invoice form. The main form in called InvoiceDetailFm. Source is the table InvoiceDetail and has invoice number, saleman, and CustID as...
5
by: Iain Miller | last post by:
Trying to get my head round building a DB to analyse phone bills. On the surface its fairly simple - duration in seconds x cost per minute/60. The problem arises with working out what time of...
3
by: Tripp Knightly | last post by:
I have a lookup table from which I want to categorize various bands of customer net income. Some of the income is positive, some is negative. The bands vary in size (ie, <500, -200 to 0, 100 to...
3
by: Kishore Gopalan | last post by:
Hi, I have the following class. Assembly: A.dll public class Customers { public Customer customer; } public class Customer { public string name;
6
by: Ron | last post by:
Hi All, Was just wondering which is faster, a subreport or dlookup. I've got a report with either 5 subreports or lots of dlookups. The subreports generally have anywhere from 5 to 12...
2
by: jonvan20 | last post by:
I have been having trouble with a simple Dlookup command that was Reccommended to me by a nice fellow named Vic, On the other hand I have statements like this that wont run they give me a run time...
4
by: =?Utf-8?B?Sm9l?= | last post by:
I have a .NET class library called NorthwindLib and a class called Customer. I have a web server that exposes a web method GetCustomer() and returns a NorthwindLib.Customer object. I want to...
3
by: hrreece | last post by:
I am trying to use the Dlookup expression in a macro to pull the value from the "Price" field in the following query. The query works fine and the Dlookup function did as well until I added a new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.