473,544 Members | 2,345 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 10753
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
8964
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...
0
1219
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++) {...
1
2234
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
1662
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
1327
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
2091
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
2907
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...
1
1816
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
1361
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
7445
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...
0
7378
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...
0
7637
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. ...
0
7727
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...
0
5940
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...
0
3427
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1853
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 we have to send another system
1
998
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
682
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...

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.