473,387 Members | 1,528 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,387 software developers and data experts.

Update many fields in a subform

157 100+
Hello guys!

I have a masterform "kg" and a subform "kg varelinjer" (order and order details in english)

In the subform i have a field named "lagerbeholdning" (storage quantity) and my problem is that i need to make a button for users which updates this field with data from another tabel on demand.

I have tried to make some code myself
Expand|Select|Wrap|Line Numbers
  1. Do While Not [Form_kg varelinjer].NewRecord
  2. [Form_kg varelinjer].Lagbeholdning.SetFocus
  3. [Form_kg varelinjer].Lagbeholdning = DLookup("lagerbeholdning", "tbl lpst00pf tdo", "varenr=" & [Form_kg varelinjer].Varenr)
  4. DoCmd.GoToRecord , , acNext
  5. Loop
But this code does not work.

I need this code
Expand|Select|Wrap|Line Numbers
  1. [Form_kg varelinjer].Lagbeholdning = DLookup("lagerbeholdning", "tbl lpst00pf tdo", "varenr=" & [Form_kg varelinjer].Varenr)
to update several records in my subform by a button on the mainform.
The reason for this is because it is very important to just update the field "lagerbeholdning" at the right time because of some fluctuating storage quantities..

Please help my find a solution
May 9 '07 #1
4 2478
ADezii
8,834 Expert 8TB
Hello guys!

I have a masterform "kg" and a subform "kg varelinjer" (order and order details in english)

In the subform i have a field named "lagerbeholdning" (storage quantity) and my problem is that i need to make a button for users which updates this field with data from another tabel on demand.

I have tried to make some code myself
Expand|Select|Wrap|Line Numbers
  1. Do While Not [Form_kg varelinjer].NewRecord
  2. [Form_kg varelinjer].Lagbeholdning.SetFocus
  3. [Form_kg varelinjer].Lagbeholdning = DLookup("lagerbeholdning", "tbl lpst00pf tdo", "varenr=" & [Form_kg varelinjer].Varenr)
  4. DoCmd.GoToRecord , , acNext
  5. Loop
But this code does not work.

I need this code
Expand|Select|Wrap|Line Numbers
  1. [Form_kg varelinjer].Lagbeholdning = DLookup("lagerbeholdning", "tbl lpst00pf tdo", "varenr=" & [Form_kg varelinjer].Varenr)
to update several records in my subform by a button on the mainform.
The reason for this is because it is very important to just update the field "lagerbeholdning" at the right time because of some fluctuating storage quantities..

Please help my find a solution
To Update the [Storage Quantity] Field in your Sub-Form from a Command Button on the Main Form using DLookup() to retrieve data from another Table, not guaranteeing the foreign language part:
Expand|Select|Wrap|Line Numbers
  1. Me![Order]![<your sub-form control name>.Form![Storage Quantity] = DLookup("lagerbeholdning", "tbl lpst00pf tdo", "varenr=" & [Form_kg varelinjer].Varenr)
May 9 '07 #2
Rabbit
12,516 Expert Mod 8TB
To refer to a control on a subform you use Me.SubformControl.Form.ControlName
May 9 '07 #3
Lysander
344 Expert 100+

I need this code
Expand|Select|Wrap|Line Numbers
  1. [Form_kg varelinjer].Lagbeholdning = DLookup("lagerbeholdning", "tbl lpst00pf tdo", "varenr=" & [Form_kg varelinjer].Varenr)
to update several records in my subform by a button on the mainform.
The reason for this is because it is very important to just update the field "lagerbeholdning" at the right time because of some fluctuating storage quantities..

Please help my find a solution
Rather than trying to update the (many) fields on the subform, try updating the subforms recordset and then refreshing the subform.

i.e. When the user clicks on the button, in the on_click event run something like docmd.RunSQL "UPDATE mytablename SET Lagbeholdning = some_value_here WHERE conditions_for_the_subform_recordset;"

Then subformname.refresh

This will update all the selected rows from your subform
May 9 '07 #4
MrDeej
157 100+
Rather than trying to update the (many) fields on the subform, try updating the subforms recordset and then refreshing the subform.

i.e. When the user clicks on the button, in the on_click event run something like docmd.RunSQL "UPDATE mytablename SET Lagbeholdning = some_value_here WHERE conditions_for_the_subform_recordset;"

Then subformname.refresh

This will update all the selected rows from your subform
This solution should be the most proffesionale i think


Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "UPDATE varelinjer SET Lagbeholdning = dlookup("lagerbeholdning", "tbl lpst00pf tdo", "varenr=" & me.varenr WHERE "ordrenummer =" & me.ordrenummer;"
But how do i solve the "Lagbeholdning = (a dynamic value that it should look up in a another table by the product number)


Thank you for all your answers!
May 10 '07 #5

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

Similar topics

1
by: Kunal | last post by:
Hi, I need some help on writing an update query to update "UnitsSold" field in Products Table whenever I save a transaction. The transaction may contain several "Subtransactions", one for each...
1
by: Jason | last post by:
I have a main form with a sub form. All the fields in the subform are mandatory. I had some code on the main form Before Update Event to check if all the fields in the sub form have data. If not, I...
5
by: Andrew | last post by:
I've got a list box that selects a record on a subform, and in that subform are a few text fiels and a button that runs an update query. How do I have the update query button run and only update...
3
by: David W. Fenton | last post by:
A very old app of mine that's been in production use, and largely unchanged since about 1998 has started recently throwing error 3188 (can't update, locked by another session on this machine) when...
0
by: Access Programming only with macros, no code | last post by:
ERROR MESSAGE: Could not update; currently locked by another session on this machine. BACKGROUND I have the following objects: Table1 - HO (which has about 51,000+ records) Table2 -...
6
by: KevinPreston | last post by:
Hello everyone, this is my first post so apologies if i dont get it right first time, i am a self taught Access user, i am stuck on something i am trying to do, briefly i have 2 tables, one for...
7
by: dscarbor | last post by:
I have a simple form with 4 fields, and a subform that retrieves records that are potential matches based on a query. The user will use the ID from the subform record and enter it into one of the...
11
by: Apple001 | last post by:
I am having trouble using SQL UPDATE statement in VBA. I have: Forms: -"frmClaim": Main form. Data is based on table "claim." It has ClaimID, and other fields. ClaimID is the auto number and...
1
by: sconard | last post by:
When you create a form based on a table via access 2007 wizard, form will update when moving from field that has changed to another field within form. Each loss of focus in "changed" fields causes...
1
by: Rosy | last post by:
I have a form "A" that is set on table vessel names. I have subform "B" that is set on table vessel info. I want form "B" to update based on what vessel I choose in form "A". I know this is...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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,...
0
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.