473,508 Members | 2,206 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add a suggested value from a related table to txt field in subform.

jhowells28
8 New Member
I have a subform for data entry purposes and I would like to populate a text box with a "suggested" value that will be pulled from a related table. I say "suggested" because the information stored in the related table is 90% accurate, but is not always correct. It would be pulling in the Product ID associated with a Purchase Order ID. If the Product ID pulled in is incorrect, however, I would like to be able to override it.

I am using Access 2000.

Can anyone help with this?

Thanks,
May 17 '07 #1
11 1942
puppydogbuddy
1,923 Recognized Expert Top Contributor
More information is needed, but based on what you have provided so far, there appears to be at least 2 ways it can be done.

1. You could set the default value property of the SuggestedValue textbox to be equal to the table value of the source field via a DLookup.
2. You could code the form's before update event procedure to do the DLookup before the form is updated.

We could assist you more if you would provide the relevant form names, table names, control names, more details about the table and fields used as the basis for the SuggestedValue.
May 18 '07 #2
jhowells28
8 New Member
More information is needed, but based on what you have provided so far, there appears to be at least 2 ways it can be done.

1. You could set the default value property of the SuggestedValue textbox to be equal to the table value of the source field via a DLookup.
2. You could code the form's before update event procedure to do the DLookup before the form is updated.

We could assist you more if you would provide the relevant form names, table names, control names, more details about the table and fields used as the basis for the SuggestedValue.
I have a habit of providing too much information, but here goes...

The tables are tblInvoices, tblPurchaseOrders, and tblPlanning. tblInvoices has a one to many enforced relationship with the tblPurchaseOrders table. tblPlanning is a production plan so it has every work order that is planned with it's corresponding item ordered. This table changes as orders are completed or filled, so I can't enforce referential integrity between tblPlanning and tblPurchaseOrders.

I have created a form based on the tblInvoices table, [frmInvoiceEntry], and added a subform, [Invoices subform], to frmInvoiceEntry. The subform is in a datasheet entry format. When the user enters the purchase order number in the first field of the subform, I want the form to automatically suggest the item ordered. The purchase order entered will not always have a corresponding purchase order in tblPlanning, so I don't want an error to appear when it doesn't work out.

If I use the DLookup function, can you illustrate what it should look like?

Thanks!
May 18 '07 #3
puppydogbuddy
1,923 Recognized Expert Top Contributor
This illustrates the use of the DLookup. You need to place the code behind your subform as code that will execute after the PO has been entered and updated.
Replace the object names I used with the actual object name in your database. The syntax used assumes that PO is a text data type.

In words the code below says if the PO entered matches a PO in tblPlanning, then the SuggestedValue control on the form is equal to the $ amount shown for that PO in the table. This amount placed by code in the SuggestedValue control can be overwritten.

[font=Times New Roman][size=3]Private Sub PO_AfterUpdate()[/size][/font]

[font=Times New Roman]If Not IsNull(Dlookup(“[PO]”, “tblPlanning”, “tblPlanning.[PO] = ‘” & Me![PO] & “’”) = True Then[/font]

[font=Times New Roman] Me![SuggestedValue].Value = Dlookup(“[POAmt]”, “tblPlanning”, “tblPlanning.[PO] = ‘” & Me![PO] & “’”) [/font]

[font=Times New Roman][size=3]End If[/size][/font]

[font=Times New Roman][size=3]End Sub[/size][/font]
May 18 '07 #4
jhowells28
8 New Member
I think I have confused you. I am not trying to get a suggested value as in a $ value, but rather just the item that was ordered. If I have an order for a car part, for example, I want to be able to enter the PO and automatically have the associated part on that order to come in as a suggested value. "Suggested" meaning I want the user to have power to override if it is incorrect or not available.

I tried the code that you gave me and I couldn't get it to work. Can you clean out the font code and resend?

This illustrates the use of the DLookup. You need to place the code behind your subform as code that will execute after the PO has been entered and updated.
Replace the object names I used with the actual object name in your database. The syntax used assumes that PO is a text data type.

In words the code below says if the PO entered matches a PO in tblPlanning, then the SuggestedValue control on the form is equal to the $ amount shown for that PO in the table. This amount placed by code in the SuggestedValue control can be overwritten.

[font=Times New Roman][size=3]Private Sub PO_AfterUpdate()[/size][/font]

[font=Times New Roman]If Not IsNull(Dlookup(“[PO]”, “tblPlanning”, “tblPlanning.[PO] = ‘” & Me![PO] & “’”) = True Then[/font]

[font=Times New Roman] Me![SuggestedValue].Value = Dlookup(“[POAmt]”, “tblPlanning”, “tblPlanning.[PO] = ‘” & Me![PO] & “’”) [/font]

[font=Times New Roman][size=3]End If[/size][/font]

[font=Times New Roman][size=3]End Sub[/size][/font]
Jul 25 '07 #5
puppydogbuddy
1,923 Recognized Expert Top Contributor
sure, sorry about the font codes..at the time I posted I did not know how to turn the font settings off: See the example without the font codes below:

Private Sub PO_AfterUpdate()

If Not IsNull(Dlookup(“[PO]”, “tblPlanning”, “tblPlanning.[PO] = ‘” & Me![PO] & “’”) = True Then

Me![SuggestedValue].Value = Dlookup(“[POAmt]”, “tblPlanning”, “tblPlanning.[PO] = ‘” & Me![PO] & “’”)

End If
Jul 25 '07 #6
jhowells28
8 New Member
I can't get this to work. I am confused #1. What is [PO] referring to? The field in the form or the field in tblPlanning or both? #2. I don't understand what field Me! [SuggestedValue].Value is referring to.

Let me explain everything more clearly. tblPlanning contains two fields: PurchaseOrderNum and ItemNum. My form is a data entry form. The order of the columns is sbfPurchaseOrderNumber, sbfProductID, sbfCostperUnit, sbfQuantity, and sbfValue (Calculated field). When a user is entering this data, I would like sbfProductID to show a suggested item number that is pulled from tblPlanning. I want the user to be able to enter to accept or type over the suggested item number if needed. This data entry writes information to tblInvoices. There is a relationship between tblInvoices and tblPlanning, but since items continually change in tblPlanning, no referential integrity can be enforced.

Please let me know if you need any more information. I really appreciate your help!


sure, sorry about the font codes..at the time I posted I did not know how to turn the font settings off: See the example without the font codes below:

Private Sub PO_AfterUpdate()

If Not IsNull(Dlookup(“[PO]”, “tblPlanning”, “tblPlanning.[PO] = ‘” & Me![PO] & “’”) = True Then

Me![SuggestedValue].Value = Dlookup(“[POAmt]”, “tblPlanning”, “tblPlanning.[PO] = ‘” & Me![PO] & “’”)

End If
Jul 25 '07 #7
puppydogbuddy
1,923 Recognized Expert Top Contributor
I can't get this to work. I am confused #1. What is [PO] referring to? The field in the form or the field in tblPlanning or both? #2. I don't understand what field Me! [SuggestedValue].Value is referring to.

Let me explain everything more clearly. tblPlanning contains two fields: PurchaseOrderNum and ItemNum. My form is a data entry form. The order of the columns is sbfPurchaseOrderNumber, sbfProductID, sbfCostperUnit, sbfQuantity, and sbfValue (Calculated field). When a user is entering this data, I would like sbfProductID to show a suggested item number that is pulled from tblPlanning. I want the user to be able to enter to accept or type over the suggested item number if needed. This data entry writes information to tblInvoices. There is a relationship between tblInvoices and tblPlanning, but since items continually change in tblPlanning, no referential integrity can be enforced.

Please let me know if you need any more information. I really appreciate your help!
Now that you have provided me the field names, and other info that you did not provide before, I have revised the DLookup, accordingly: Let me know right away if it is not working the way you want it to.

__________________________________________________ ____________
Try placing this code behind your data entry subform
RE: Me>>>>if focus is on the main form, me is a quick reference to the main form
>>>>>>>>>if focus is on the subform, me refers to the subform
Me.Parent>>>>focus is on the subform, but you want to reference an object on the form

Essentially, the procedure below says “ after entering the order # on the subform, check for and see if an itemNum exists for the order # in tblPlanning. If it does, then copy the suggested itemNum in tblPlanning to sbfProductID.
__________________________________________________ ______________

Private Sub sbfPurchaseOrderNumber_AfterUpdate()

If Not IsNull(Dlookup(“[ItemNum]”, “tblPlanning”, “tblPlanning.[ PurchaseOrderNum] = ‘” & Me![sbfPurchaseOrderNumber] & “’”) = True Then

Me![sbfProductID].Value = Dlookup(“[ItemNum]”, “tblPlanning”, “tblPlanning.[ PurchaseOrderNum] = ‘” & Me![sbfPurchaseOrderNumber] & “’”)

End If
Jul 25 '07 #8
jhowells28
8 New Member
I put the code in, however, I get an error that says:

Compile Error:

Expected: list separator or )

I don't know what this means. Apparently I'm missing a braket or something, but I copied your code and pasted it in.
Jul 26 '07 #9
puppydogbuddy
1,923 Recognized Expert Top Contributor
I put the code in, however, I get an error that says:

Compile Error:

Expected: list separator or )

I don't know what this means. Apparently I'm missing a braket or something, but I copied your code and pasted it in.
Try it now:
Expand|Select|Wrap|Line Numbers
  1. Private Sub sbfPurchaseOrderNumber_AfterUpdate()
  2.  
  3. If Not IsNull(Dlookup(“[ItemNum]”, “tblPlanning”, “tblPlanning.[PurchaseOrderNum] = ‘” & Me![sbfPurchaseOrderNumber] & “’”)) = True Then
  4.  
  5. Me![sbfProductID].Value = Dlookup(“[ItemNum]”, “tblPlanning”, “tblPlanning.[PurchaseOrderNum] = ‘” & Me![sbfPurchaseOrderNumber] & “’”)
  6.  
  7. End If
  8. End Sub
  9.  
Jul 26 '07 #10
jhowells28
8 New Member
This just never worked for me. I appreciate your help.
Mar 10 '08 #11
puppydogbuddy
1,923 Recognized Expert Top Contributor
This just never worked for me. I appreciate your help.
Why did wait until now to respond? Your last response was July 2007. If you had gotten back to me sooner, I could have fixed the syntax problem. You need to understand that site experts are not at your computer, so we are dependent on feedback from you to present the problem correctly and tell us what is happening when you implement our suggestions.
Mar 10 '08 #12

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

Similar topics

4
2031
by: Mark Hanley | last post by:
I have found similar problems to mine on this and other newsgroups but I still haven't been able to solve my problem... I have two tables 'Pupil' and 'SEN' which are related on a field called...
2
8199
by: Terry Bickle | last post by:
Please forgive me for using the wrong term here or there. I'm an old Excel 4 macro guy who didn't convert to VB and I'm tinkering with an Access 2000 DB. I'm sure there is a simple Access 101...
3
1843
by: Donna Price | last post by:
I have a problem with a database which I've recently separated into several related tables. I have a main data entry form, which has several subforms on it on tabbed pages. The first subform is...
1
3420
by: Mike | last post by:
I have a form that has an embedded subform (Datasheet View) that are linked based on a 1-many ID field. I have a field (SET) in my embedded subform that I want to Autoincrement starting with...
9
9667
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
5
3202
by: vsteshenko | last post by:
Hello, This is my second post to the any usernet group and the first one was posted to the wrong one. I am currently working on creating an order form for sales associates at my work to be used...
4
2026
by: rczuba | last post by:
Problem: Creating a Default Value for a field in a subform when a field in the subform & form match. I'm trying to create a payroll database for a small home business that I have that has had...
2
1758
by: nospam | last post by:
-------------------------------------------------------------------------------- I have a subform with the related IDs for each customer on the customer main form. I have a button on the...
6
10738
by: solom190 | last post by:
Okay this is the situation I have two forms and they have a 1:M relationship. I don't have enough space screen-wise to do a traditional "drag form to form" to create a subform so what I did was...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
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,...
1
7046
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
7498
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...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1557
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.