473,796 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help updating a control in a subform automatically

3 New Member
I have created a MS access DB to track transport costs for tax purposes.

I enter data into a main form [F_car] that tracks miles traveled by date with a subform [F_tolls subform]. The subform has fields for the date traveled [date], toll location [toll site] and the cost of the toll [cost]. The date on the subform is copied from the main form. [toll site] is a combo box that draws its values from [toll name] in the [key- Toll codes] table, which also has the fields -Toll ID, Toll text, and toll cost).

My question is regarding the [cost] control on the subform. I would like the cost to be filled in automatically from the [key- Toll codes] table [toll cost] field whenever a toll location is chosen from the combo box.

Being a beginner user of Access, I looked to the Internet for help and have been unsuccessful in trying the following:

-using the following Dlookup function as the control source for the cost text box

=DLookUp("[Toll cost]","Key-Toll codes","[Toll name] = ' " & [Tolls site] & " ' ")

- using the following after update event procedure with the [toll site] combo box

Private Sub Tolls_site_Afte rUpdate()
Me![Cost] = DLookup("[Toll cost]", "Key-Toll codes", "[Toll name] = ' " & [Tolls site] & " ' ")
End Sub

Can someone suggest the right way to do this?
Sep 13 '06 #1
4 2105
PEB
1,418 Recognized Expert Top Contributor
Hi,

Use

Me![Tolls site]
or
Forms![Your form]![Tolls site]

And a question?

What is the name of your combo box? [Tolls site] ? Or other?

:)
Sep 13 '06 #2
froglog
3 New Member
Hi,

Use

Me![Tolls site]
or
Forms![Your form]![Tolls site]

And a question?

What is the name of your combo box? [Tolls site] ? Or other?

:)

HI,

Thanks for the reply.

[Tolls site] is the name of my combo box

I used the following event procedure code with the [toll site] combo box after substituting
Me![Tolls site] in place of [Tolls site] in criteria portion of the Dlookup function:


Private Sub Tolls_site_Afte rUpdate()
Me![Cost] = DLookup("[Toll cost]", "Key-Toll codes", "[Toll name] = ' " & Me![Tolls site] & " ' ")
End Sub

When I created a new record as a test and selected a toll site, the [cost] text box went from $0.00 to a blank box.

However, if I modify the criteria to reflect a specific toll site (2m), the cost value for that toll site pops into [cost] each time I choose a site from the combo box.

Private Sub Tolls_site_Afte rUpdate()
Me![Cost] = DLookup("[Toll cost]", "Key-Toll codes", "[Toll name] = '2m ' ")
End Sub


The row source for the [toll site] combo box is SELECT [Key-Toll codes].[Toll ID], [Key-Toll codes].[Toll name] FROM [Key-Toll codes] ORDER BY [Key-Toll codes].[Toll name]; and column 1 is bound.

Why does the Dlookup function recognise a specifc toll site when I use it in the criteria, but not the value that is chosen from the combo box? Is there something in the properties of the combo box or underlying [Key- Toll codes] table that I may need to check/change?
Sep 13 '06 #3
PEB
1,418 Recognized Expert Top Contributor
Why do not change the columns in your combo?

Do the first column this that you need and second the id!

What is the text in your combo that is shown?

:)
Sep 13 '06 #4
froglog
3 New Member
Why do not change the columns in your combo?

Do the first column this that you need and second the id!

What is the text in your combo that is shown?

:)
HI,

Switching order of the columns made no difference, but I solved the problem anyway.

For future reference, my combo box contained more than one column and only when I changed the criteria in the Dlookup function to refer to the column that was actually bound (which was different from the one I saw displayed in the combo box) did my code function as expected.
Sep 13 '06 #5

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

Similar topics

1
2593
by: Gerry Abbott | last post by:
Hi all, I've got two subforms on an unbound form, frmMain, frmSubOne, frmSubTwo. Ive got a control on frmSubTwo, cboList, a list box, which draws its source from the table underlying frmSubOne. I want this list to be kept automatically up to date, for selection, so after updating frmSubOne, the new records will be visible in the cboList box when selected.
3
1961
by: Earthling | last post by:
Any help would be appreciated to solve the following simple problem that I will describe. *** There is a form called "red chocolate form". The form has a particular subform field that has a checkmark box that is selectable as on or off (on if there is a checkmark inside it). The table that contains the data for the form is known as "red chocolate
5
2446
by: Mary Litten | last post by:
Hi - (This is my very first post) I have gotten to this point of registering to post because I have been spinning my wheels so long, I believe I am all caught up in the weeds. (and mud) I have a form, that has several tabs. On one tab, I have a subform (wr_completion_subform). This subform is bound to a table (wr_completion_table). On the subform, I have a button from which I have added code to email a report of the completion data...
3
3615
by: Paul T. Rong | last post by:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice should apear automatically next to the product name in the subform. Is it possible? How do I do this? Thanks in advance. Paul from Slovakia
7
1341
by: Swilson513 | last post by:
I'm trying to make what should be a simple DB, but have done got myself confused. I'm trying to keep track of the contents of several kits that use common components. Each component has a unique number and each kit has a unique number. I would like to be able to pull up the kit number them choose the individual components that are included in that kit and keep that record so if any components are changed it would update the kit.
5
2639
by: Richard Stanton | last post by:
Hello all My database has a main form linked to table1. It has several subforms on the main form, all linked to table2. Table1 and Table2 are linked by primary/foreign key, no duplicates allowed, one-to-one. If I update field(s) on a single subform it works fine but when I update fields on multiple subforms ie without closing the form between updates, I get the following error:
3
6338
by: | last post by:
Hello, I have created an ASP.NET 2.0 application that utilized a Gridview Control to display and update/delete data. The problem I am having is that the gridview control is displaying the data correctly but it is not updating or deleting the rows. What I did was, in design view, added a gridview control and added an sqldatasource control. I configured the data source to update and delete. In the gridview tasks I selected enable...
1
2720
by: rdemyan via AccessMonster.com | last post by:
My App has 10 or so tables that we provide that contains proprietary data. This data will need to be updated once or twice a year. I would like some comments, suggestions on my proposed strategy for updating these tables via an ftp site: 1) Post a .mdb file to our ftp web site that contains the updated tables. My App code connects to the ftp site and gets the file name for any update files on the site. I already have code to do this...
17
2616
by: lokidog | last post by:
I am trying to automatically transfer data from one textbox to another between subforms within a 'main' form. I put this code into the Gotfocus eventprocedure: Private Sub Date_GotFocus() If Len(Trim$(Me!.Value & "")) = 0 Then 'This checks for blank or space-filled date field - it will only transfer data if it has not already been entered. Me! = !!.!.! SendKeys "{F2}" SendKeys "{TAB}"
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9535
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10467
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10021
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.