473,836 Members | 1,586 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

update table from list using recordsets

gcoaster
117 New Member
Hello,
* Access 2007
* Little Experience with VBA

I will try and make this as clear as I can.

ISSUE

I have a database that has information for Clients and their Computers.

I am trying to make a subform linked to each Computer

The Subform shows me the entire list of software titles in one box.
Box 2 shows me which titles have been installed.

I would like to pick which title(s) that are installed on each machine listed in box 2.

For instance
Matts Computer has AVG installed, Office 2007 installed and Foxit.

when I go back to Matts Computer Record, I would like to see which titles have been installed and easily update on the fly.

Box 1 showing all software titles and filtering out
( AVG installed, Office 2007 installed and Foxit. )

Box 2 showing which titles are already installed [3]
( AVG installed, Office 2007 installed and Foxit. )

From Box 1 I can select, multiselect titles and update BOX 2.


Please help
thank you
Gcoaster
Nov 5 '07 #1
14 3649
Rabbit
12,516 Recognized Expert Moderator MVP
You need to create a VBA function to loop through a recordset. The following tutorial gives you the basics even though it's not like your situation. Basic DAO recordset loop using two recordsets
Nov 7 '07 #2
gcoaster
117 New Member
I think I understand.

Expand|Select|Wrap|Line Numbers
  1. Function yourFunctionName() 
  2. Dim db As DAO.Database
  3. Dim rs1 As DAO.Recordset
  4. Dim rs2 As DAO.Recordset
  5.  
  6.   Set db = CurrentDb() 
  7.   Set rs1 = db.OpenRecordset("Query1") 
  8.   Set rs2 = db.OpenRecordset("Query2")
  9.  
  10.   If rs1.RecordCount=0 Then Exit Sub
  11.  
  12.   rs1.MoveFirst 
  13.   ' loop through each record in the first recordset
  14.   Do Until rs1.EOF
  15.     ' If matching record is found then update field in 
  16.     ' second recordset to value you determine
  17.    If rs2.RecordCount=0 Then Exit Sub
  18.     rs2.MoveFirst
  19.     Do Until rs2.EOF
  20.       If rs1![FieldName] = rs2!FieldName Then
  21.         rs2.Edit
  22.         rs2![FieldName] = 'Your Value'
  23.         rs2.Update
  24.       End If
  25.       rs2.MoveNext
  26.     Loop
  27.     rs1.MoveNext
  28.   Loop
  29.  
  30.   rs1.Close 
  31.   rs2.Close 
  32.   Set rs1 = Nothing
  33.   Set rs2 = Nothing
  34.   Set db = Nothing
  35.  
  36. End Function
Nov 13 '07 #3
gcoaster
117 New Member
Hello Rabbit,
Have read some of your posts, you are a master! cool..
this is how far i have gotten. left to right is not working. please help

thank you
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3. Private Sub btnRight_Click()
  4.     If Not IsNull(Me.lbxLeft.Column(0, Me.lbxLeft.ListIndex)) Then
  5.     CurrentDb.Execute "UPDATE MACHINE_SOFTWARE SET installed=Yes WHERE machineSoftwareID=" & Me.lbxLeft.Column(0, Me.lbxLeft.ListIndex) & ";"
  6.     Me.Refresh
  7.     Else
  8.       MsgBox "Please select an entry"
  9.     End If
  10. End Sub
  11. Private Sub btnRightAll_Click()
  12.     CurrentDb.Execute "UPDATE TEMP_SOFTWARE SET installed=Yes;"
  13.     Me.Refresh
  14. End Sub
  15. Private Sub btnLeft_Click()
  16.     If Not IsNull(Me.lbxRight.Column(0, Me.lbxRight.ListIndex)) Then
  17.     CurrentDb.Execute "UPDATE TEMP_SOFTWARE SET installed=Yes WHERE softwareID=" & Me.lbxRight.Column(0, Me.lbxRight.ListIndex) & ";"
  18.     Me.Refresh
  19.     Else
  20.       MsgBox "Please select an entry"
  21.     End If
  22. End Sub
  23. Private Sub btnLeftAll_Click()
  24.     CurrentDb.Execute "UPDATE TEMP_SOFTWARE SET installed=No;"
  25.     Me.Refresh
  26. End Sub
  27. Private Sub Form_Current()
  28. Dim dbs As DAO.Database
  29.     Dim sSQL As String
  30.     Set dbs = CurrentDb()
  31.     ' 1) Delete and then update records
  32.     sSQL = "DELETE FROM TEMP_SOFTWARE"
  33.     dbs.Execute sSQL
  34.     sSQL = "INSERT INTO TEMP_SOFTWARE ( title )SELECT SOFTWARE.title FROM SOFTWARE"
  35.     dbs.Execute sSQL
  36.     Me.Refresh
  37. End Sub
Nov 13 '07 #4
Rabbit
12,516 Recognized Expert Moderator MVP
I think I misunderstood your original intention. I originally thought you had multiple records for each computer and wanted to create a single string. However, that does not seem to be the case. What is the structure of your software table?
Nov 13 '07 #5
gcoaster
117 New Member
Thank you Rabbit!
here is the structure of Software, and other tables just in case.
( trying to upload it but... File Too Large. Limit for this filetype is 97.7 KB. my file is 225.5 KB.) I managed to, split file in 3 parts.


Table: MACHINE_SOFTWAR E
machineSoftware ID Long Integer 4
machineFK Long Integer 4
softdCat Text 255
softdSubCat Text 255
softdType Text 255
softdSubType Text 255
title Text 255
publisher Text 255
url Text 255
installed Yes/No 1

Table: SOFTWARE
softwareID Long Integer 4
SoftCat Text 255
softSubCat Text 255
type Text 255
subType Text 255
title Text 255
dateUpdated Date/Time 8
publisher Text 255
homepage Text 255
version Text 255
description Memo

Table: TEMP_SOFTWARE
tempSoftwareID Long Integer
machineSoftFK Long Integer
SoftCat Text 255
softSubCat Text 255
type Text 255
subType Text 255
title Text 255
dateUpdated Date/Time 8
publisher Text 255
homepage Text 255
version Text 255
description Memo -
installed Yes/No 1

Table: MACHINE
machineID Long Integer 4
clientFK Long Integer 4
softwareFK Text 255
productFK Long Integer 4
machineNotes Memo
Attached Files
File Type: zip 1.zip (49.0 KB, 125 views)
File Type: zip 2.zip (48.9 KB, 129 views)
File Type: zip 3.zip (17.9 KB, 117 views)
Nov 14 '07 #6
Rabbit
12,516 Recognized Expert Moderator MVP
If I understand correctly you have one record for each piece of software on each machine. And what you want to do is have 2 list boxes, one lists all software that the chosen machine does NOT have and the other lists the software it does have. Then the user can select one or more software from either listbox, click a button, and either create new records or delete records and requery the listboxes?
Nov 14 '07 #7
gcoaster
117 New Member
If I understand correctly you have one record for each piece of software on each machine. And what you want to do is have 2 list boxes, one lists all software that the chosen machine does NOT have and the other lists the software it does have. Then the user can select one or more software from either listbox, click a button, and either create new records or delete records and requery the listboxes?
Thank you Rabbit,
Yes EXACTLY!!!
by the way,
I am the user, Only I will be using this. I am trying to get away from outlook2007 +bcm.
Nov 16 '07 #8
Rabbit
12,516 Recognized Expert Moderator MVP
Displaying the items for the listboxes is easy. For the listbox with uninstalled software, you use an unmatched query, for the other, a regular select query will suffice. Just make sure you take into account the computer in question. You'll also want to rebuild the control source string for each listbox in the Current event of the form.

As for moving software back and forth, you'll have two command buttons, one to add and one to delete. If you have a multi-select listbox then you'll have to loop a DoCmd.RunSQL. Then you want to requery both listboxes
Nov 16 '07 #9
gcoaster
117 New Member
Hello Rabbit,
thank you for your on going support.

I took a different route this time, things I changed where some of the table and form names to make it esier, learned its important working with VBA NOT to name the form and table the same. it gets confusing! .

almost there now, one error is keeping me. and that is deleting software from right. learning about the DoCmd.RunSQL

Am I doing things right? thank you agian.


Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.  
  3.   Me.lstInstalled.RowSource = "SELECT MACHINESOFTWARE.title FROM MACHINESOFTWARE " & _
  4.                               "WHERE MACHINESOFTWARE.client = forms![MACHINE]!cboFullName"
  5.  
  6.  
  7.   Me.lstSoftware.RowSource = "SELECT tblSOFTWARE.title FROM tblSOFTWARE " & _
  8.                                  "WHERE tblSOFTWARE.title NOT IN " & _
  9.                                  "(SELECT MACHINESOFTWARE.title FROM MACHINESOFTWARE " & _
  10.                                  "WHERE MACHINESOFTWARE.client = forms![MACHINE]!cboFullName)"
  11.  
  12. End Sub
  13.  
  14. Private Sub lstInstall_Click()
  15.   If IsNull(Me.lstInstalled) And Not IsNull(Me.lstSoftware) Then
  16.  
  17.     'Dim MyMessage
  18.     'MyMessage = MsgBox("This will add a new installation to this record.  Continue?", vbYesNoCancel)
  19.   'If MyMessage = vbYes Then
  20.  
  21. Dim db As DAO.Database
  22. Dim rs As DAO.Recordset
  23.  
  24. Set rs = Me.RecordsetClone
  25.  
  26.   With rs
  27.  
  28.     .AddNew
  29.  
  30.     !client = Forms!machine!cboFullName
  31.     !machineName = Forms!machine!machineName
  32.     !title = Me.lstSoftware
  33.  
  34.     .Update
  35.  
  36.   End With
  37.  
  38.     Me.lstInstalled.Requery
  39.     Me.lstSoftware.Requery
  40.  
  41.     Me.lstInstalled = Null
  42.     Me.lstSoftware = Null
  43.  
  44. Set rs = Nothing
  45.  
  46.   End If
  47.     'Else: MsgBox "Please select only a software to install", vbOKOnly
  48.   'End If
  49.  
  50. End Sub
  51.  
  52. Private Sub lstRemove_Click()
  53.  
  54.   If IsNull(Me.lstSoftware) And Not IsNull(Me.lstInstalled) Then
  55.  
  56.     Dim MyMessage
  57.     MyMessage = MsgBox("This will delete the selected software's record from this machine.  Continue?", vbYesNoCancel)
  58.   If MyMessage = vbYes Then
  59.  
  60.   DoCmd.RunSQL "DELETE * FROM MACHINESOFTWARE WHERE MACHINESOFTWARE.client =Forms!machine!cboFullName AND " & _
  61.     " MACHINESOFTWARE.machineName =Forms!machine!machineName AND " & _
  62.     " MACHINESOFTWARE.title =Forms!MACHINEsoft!lstInstalled "
  63.  
  64.     Me.lstInstalled.Requery
  65.     Me.lstSoftware.Requery
  66.  
  67.     Me.lstInstalled = Null
  68.     Me.lstSoftware = Null
  69.  
  70.   End If
  71.   Else: MsgBox "Please select only a software to Uninstall", vbOKOnly
  72.   End If
  73.  
  74. End Sub
Nov 16 '07 #10

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

Similar topics

0
2787
by: Sue Adams | last post by:
I actually have two issues/questions: I have an autonumber field in an access db table that I grab and later use to update a record in another table withing the same db. The code I use to get it from the db table is: ''Retrieve the Registration Identification Number strRegisterID = Rs("Register_ID") Prior to testing my code and actually updating the db, I''m trying to write it to the page to make sure their isn''t a loop or massive...
12
22954
by: jimserac | last post by:
I had previously posted this in an Access forum with negative results so will try here. Although this question specifies an Access database, I also wish to accomplish this with a large MS SQL Server database that we have. Question follows: The following SQL statement, used in VBScript,
10
9827
by: Steve Jorgensen | last post by:
Hi all, Over the years, I have had to keep dealing with the same Access restriction - that you can't update a table in a statement that joins it to another non-updateable query or employs a non-updateable subquery. I run across this problem again and again, and yet I've never come up with a single, universal work-around. I'm wondering what other people here are doing.
9
4365
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my predecessor, I hasten to add) so that each day it creates a copy of the record for each company, changes the date to today's date, and prompts the user for any changes of ratings on that day. The resulting data table grows by approx 600 records per...
0
9666
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
10838
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
9369
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
7788
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
6977
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
5645
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
5821
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4447
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
2
4010
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.