473,499 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating a form form another table

I have a form that users enter information into. What I want to do is
to update certain fields from another table once they have entered a
number in a field. The form is already based on a query as this allows
the user to see only the records they entered. What would be the best
approach to this?

TIA,

Cyberwolf

Jan 4 '07 #1
4 1594
I'd probably do something like (and this is just an example that you
will need to adapt to your needs) ...

dim db as database
dim rec as recordset
dim var1, var2, var3 as variant

set db = currentdb
set rec = db.openrecordset ("OtherTable")

var1 = me.field1
var2 = me.field2
var3 = me.field3

LUpdate = "UPDATE rec" & _
LUpdate = LUpdate & " set [field1] = var1," & _
LUpdate = LUpdate & " [field2] = var2 " & _
LUpdate = LUpdate & " WHERE [field3] = var3 "

db.Execute LUpdate, dbFailOnError

Cyberwolf wrote:
I have a form that users enter information into. What I want to do is
to update certain fields from another table once they have entered a
number in a field. The form is already based on a query as this allows
the user to see only the records they entered. What would be the best
approach to this?

TIA,

Cyberwolf
Jan 4 '07 #2
On 4 Jan 2007 12:10:58 -0800, "ManningFan" <ma********@gmail.comwrote:
>I'd probably do something like (and this is just an example that you
will need to adapt to your needs) ...

dim db as database
dim rec as recordset
dim var1, var2, var3 as variant

set db = currentdb
set rec = db.openrecordset ("OtherTable")

var1 = me.field1
var2 = me.field2
var3 = me.field3

LUpdate = "UPDATE rec" & _
LUpdate = LUpdate & " set [field1] = var1," & _
LUpdate = LUpdate & " [field2] = var2 " & _
LUpdate = LUpdate & " WHERE [field3] = var3 "

db.Execute LUpdate, dbFailOnError

There is no need for a recordset. The SQL is executed directly on the table
specified (tblMyTable) and the variables need to be concatenated within the SQL
string ie Set [field1]=var1 will not work, it needs to be SET [field1]=" & var1
etc

strSQL = "UPDATE tblMyTable SET [field1]=" & var1 & ", " _
& "[field2]=" & var2 & ", [field3]=" & var3 & ";"

CurrentDB.Execute strSQL, dbFailOnError

Wayne Gillespie
Gosford NSW Australia
Jan 4 '07 #3
OK, so how does the SQl know which record to look at? ANd, is my code
below correct?

Dim var1, var2, var3 As Variant
var1 = [Current TB].[Claim Number]
var2 = [Current TB].Amount
var3 = [Current TB].Store

strSQL = "UPDATE Chargebacks SET [Ref#]=" & var1 & ", " _
& "[Amount]=" & var2 & ", [Store]=" & var3 & ";"
On Jan 4, 5:05 pm, Wayne Gillespie <best...@NOhotmailSPAM.com.au>
wrote:
On 4 Jan 2007 12:10:58 -0800, "ManningFan" <manning...@gmail.comwrote:


I'd probably do something like (and this is just an example that you
will need to adapt to your needs) ...
dim db as database
dim rec as recordset
dim var1, var2, var3 as variant
set db = currentdb
set rec = db.openrecordset ("OtherTable")
var1 = me.field1
var2 = me.field2
var3 = me.field3
LUpdate = "UPDATE rec" & _
LUpdate = LUpdate & " set [field1] = var1," & _
LUpdate = LUpdate & " [field2] = var2 " & _
LUpdate = LUpdate & " WHERE [field3] = var3 "
db.Execute LUpdate, dbFailOnErrorThere is no need for a recordset. The SQL is executed directly on the table
specified (tblMyTable) and the variables need to be concatenated within the SQL
string ie Set [field1]=var1 will not work, it needs to be SET [field1]=" & var1
etc

strSQL = "UPDATE tblMyTable SET [field1]=" & var1 & ", " _
& "[field2]=" & var2 & ", [field3]=" & var3 & ";"

CurrentDB.Execute strSQL, dbFailOnError

Wayne Gillespie
Gosford NSW Australia- Hide quoted text -- Show quoted text -
Jan 24 '07 #4
On 24 Jan 2007 10:40:35 -0800, "Cyberwolf" <cy**********@gmail.comwrote:
>OK, so how does the SQl know which record to look at? ANd, is my code
below correct?

Dim var1, var2, var3 As Variant
var1 = [Current TB].[Claim Number]
var2 = [Current TB].Amount
var3 = [Current TB].Store

strSQL = "UPDATE Chargebacks SET [Ref#]=" & var1 & ", " _
& "[Amount]=" & var2 & ", [Store]=" & var3 & ";"

The sql string looks Ok as long as var1, 2 and 3 are numeric. If any of them are
text they need to be wrapped in quotes. (I use Chr(34) for clarity).
eg [Store]=" & Chr(34) & var3 & Chr(34) & ";"

To have the update performed on specific record(s) you need to add a WHERE
clause to the string to define the record(s).

Assuming you wish to update the record currently displayed in your form, you
would add something like this -

strSQL = "UPDATE Chargebacks SET [Ref#]=" & var1 & ", " _
& "[Amount]=" & var2 & ", [Store]=" & var3 & _
& "WHERE MyIDField = " & Me.MyIDControl & ";"
Wayne Gillespie
Gosford NSW Australia
Jan 24 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2943
by: | last post by:
Hello, Sorry to ask what is probably a simple answer, but I am having problems updating a table/database from a PHP/ PHTML file. I can Read From the Table, I can Insert into Table/Database, But...
11
16069
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
1
2300
by: Derek Davlut | last post by:
I have a Table that contains data that I use in a query to manipulte the data through expressions. I have a form that uses the query for manipulating the data. How do I write the changed values...
10
5624
by: jaYPee | last post by:
does anyone experienced slowness when updating a dataset using AcceptChanges? when calling this code it takes many seconds to update the database SqlDataAdapter1.Update(DsStudentCourse1)...
6
3666
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
3
1768
by: Spoogledrummer | last post by:
Hi it's me again, still working on the sam 5 minute problem so feeling kind of thick now. I've dumped the idea of using a textarea for now and am using a textbox instead but am struggling when it...
9
2504
by: hrreece | last post by:
I have an Access 2002 database that has a form that can be used to review individual records. At the bottom of the form are buttons that are linked to functions that allow the user to "Find a record...
5
7415
stepterr
by: stepterr | last post by:
I have a form that is built based on a query. Everything is working except when I submit the form the radio buttons are only updating the first row in my database. dcategory and dthumbnail are two...
4
2598
by: AlexNunley | last post by:
I've adopted a moderately sized (65k records) active use database (Access 2000, Windows XP). One of the most commonly used forms is whats called the RMA generation field, used to add claim...
2
3297
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Hi All! I am with a situation where I am not getting the right updating to the form's fields. The situation is the following one: I have one combobox and one textbox. I am using the...
0
7134
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
7229
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...
1
6905
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
7395
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
4921
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
4609
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
3108
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...
0
1429
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
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.