473,608 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to update multiple records in MS Access database from a list in a form

1 New Member
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound) that displays the new Top 30 positions with additional information defined in the form such as Date Entered chart, Highest Position, etc. I have a command button (Update) that will launch an event to update each table entry for each record shown on the form. This event needs to loop through the records displayed in the form and then find the corresponding record in the database table and update certain fields. The following will successfully go through each record on the form but I am stuck with the coding to find the original record in the database (via its unique Record Number ID). FindFirst or a SQL statement gives a runtime error that states 'syntax error'.
What am I missing?
NB: I've commented out some code until I can confirm the search process works.

Private Sub Update_New_Info _Click()
'Update all entries then exit.

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim rstForm As DAO.Recordset

Dim W4SEARCH As String
Dim W4SQLCMD As String
Dim W4SQL As String

'Get the database and recordset
Set dbs = CurrentDb
Set rst = CurrentDb.OpenR ecordset("TSSIN GLE-WEEKLY")
'Set rstForm = Forms!Form_WCE1 40_FRM.Form.Rec ordset
Set rstForm = Forms!WCE140_FR M.Form.Recordse t

'Define SQL statement
'W4SQLCMD = "UPDATE TSSINGLE-WEEKLY " & _
'(cntd)

W4SQLCMD = "UPDATE rst SET " & _
"rst![SWHIGHPOSN] = Forms!WCE140_FR M.Form!F1HIGHPO SN, " & _
"rst![SWWKSTOP30] = Forms!WCE140_FR M.Form!F1WKSTOP 30, " & _
"rst![SWWKSTOP75] = Forms!WCE140_FR M.Form!F1WKSTOP 75, " & _
"rst![SWFIRST30] = Forms!WCE140_FR M.Form!F1FIRST3 0, " & _
"rst![SWHIGHYEAR] = Forms!WCE140_FR M.Form!F1HIGHYE AR, " & _
"rst![SWWK30YEAR] = Forms!WCE140_FR M.Form!F1WK30YE AR, " & _
"rst![SWLEFT30] = Forms!WCE140_FR M.Form!F1LEFT30 , " & _
"rst![SWLEFT75] = Forms!WCE140_FR M.Form!F1LEFT75 , " & _
"rst![SWYEAR] = Forms!WCE140_FR M.Form!F1YEAR " & _
"WHERE rst![SWRECID] = Forms!WCE140_FR M.Form!SWRECID"

'"IIf (Forms!WCE140_F RM.Form!F1LEFT7 5' <> Null And rst![SWYEAR] = Null, " & _
'"rst![SWYEAR] = Year(Forms!WCE1 40_FRM.Form!F1L EFT75), rst![SWYEAR]) " & _


'Process all records
DoCmd.GoToRecor d , , acFirst
rstForm.MoveFir st

Do While Not rstForm.EOF

'Find record via RRN
W4SEARCH = "[SWRECID] = Forms!WCE140_FR M.Form!SWRECID"

' Set rst = CurrentDb.OpenR ecordset("TSSIN GLE-WEEKLY")
' Set dbs = CurrentDb

W4SQL = ""
W4SQL = W4SQL & "SELECT * FROM TSSINGLE-WEEKLY "
W4SQL = W4SQL & "WHERE TSSINGLE-WEEKLY.SWRECID = " & Forms!WCE140_FR M.Form!SWRECID

' MsgBox W4SQL
' CurrentDb.Execu te W4SQL
' DoCmd.RunSQL W4SQL
' rst.FindFirst rst![SWRECID] = Forms!WCE140_FR M.Form!SWRECID

' DoCmd.FindRecor d W4SEARCH

' rst![SWHIGHPOSN] = Forms!WCE140_FR M.Form!F1HIGHPO SN
' rst![SWWKSTOP30] = Forms!WCE140_FR M.Form!F1WKSTOP 30
' rst![SWWKSTOP75] = Forms!WCE140_FR M.Form!F1WKSTOP 75
' rst![SWFIRST30] = Forms!WCE140_FR M.Form!F1FIRST3 0
' rst![SWHIGHYEAR] = Forms!WCE140_FR M.Form!F1HIGHYE AR
' rst![SWWK30YEAR] = Forms!WCE140_FR M.Form!F1WK30YE AR
' rst![SWLEFT30] = Forms!WCE140_FR M.Form!F1LEFT30
' rst![SWLEFT75] = Forms!WCE140_FR M.Form!F1LEFT75
' If Forms!WCE140_FR M.Form!F1LEFT75 <> Null And rst![SWYEAR] = Null Then
' rst![SWYEAR] = Year(Forms!WCE1 40_FRM.Form!F1L EFT75)
' End If
' rst.Update

' Set rstForm = Forms!WCE140_FR M.Form.Recordse t
' DoCmd.GoToRecor d , , acNext

' DEBUG - Show record ID for Form and for Table
MsgBox "Form RRN is " & Forms!WCE140_FR M.Form!SWRECID & "File RRN is " & rst![SWRECID]
rstForm.MoveNex t
' MsgBox "Record ID is " & Forms!WCE140_FR M.Form!SWRECID
Loop

'MsgBox "SQL is " & W4SQLCMD
'DoCmd.RunSQL W4SQLCMD

'Exit
DoCmd.Close

End Sub
Mar 10 '24 #1
1 10770
cactusdata
214 Recognized Expert New Member
Why don't you bind the form to the table?
That will leave you with zero code.
Mar 13 '24 #2

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

Similar topics

4
8973
by: Mark S. | last post by:
Hi, I have a weird UPDATE sequence I want to perform. The customer does not want to use INSERT and DELETE. My issue is that there are multiple Mat_Class, but I do not wish to hard code each one individually. Originally I was thinking of using a select statement and creating a loop to sub in each Mat_Class but I really have no idea how to make that work purely in SQL. This is going to be run as a DTS procedure overnight. Any help would...
0
1230
by: jack daniels via .NET 247 | last post by:
Hi! Perhaps you know of a better way here. I have an Access database, actually a single table. Now, at the click of a button on a C# Form, each and every single cell associated with the primary keys has to be updated. I have the new cell values in an arraylist and this is what I am doing: for (int i = 0; i < numberOfPrimaryKeys; i++) { adapter.UpdateCommand = new OleDbCommand(strSQL, conn); adapter.UpdateCommand.ExecuteNonQuery(); }
1
2243
by: A P | last post by:
How can I go about updating multiple records or deleting multiple records from a DB at a time?
1
1669
by: Kenneth | last post by:
Dear all, How can I update multiple records in using ASP.NET? Currently I have a table which require to update frequently but I can update records one by one using DataGrid. Kenneth
1
1333
by: soniasherry | last post by:
Can I please get some guidance.I'm new to MSACCESS 2003 How do I update all the tables in a main access database file with around 50 tables with unique records from similar tables placed in another access database file.
1
2102
by: jllopez | last post by:
I need update multiple records in the datagrid but this is using ASP.net and VB, somebody that I can help?
2
2913
by: susinthaa | last post by:
Hi, we are having some text values in the variable of the VB form and we have to insert these datas into the MS Access database. We have opened the database and only one record is inserted in the DB and the latest records are over wiritng the old one. Below is the codings for updating the database. Please help me how to insert the fields in the next row in the DB. Public Function fopendb(prjname)
1
1820
Fary4u
by: Fary4u | last post by:
how can i update multiple records corresponding to perticular ID & update values in one go ? mode_a contains ID No. Dim mode,mode_a,i mode=Request("t1") mode_a=split(mode,",")
5
1367
by: garymilam | last post by:
I have a date closed field on a form. How do I make this field update multiple records. For example. I have books database. I have multiple books checked out with a date. I want to update the checkout date from my checkout form on multiple records which is a continuous form. Please help
0
8087
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
8493
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8365
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
6847
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
6023
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
5499
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3993
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...
0
4053
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1620
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.