473,466 Members | 1,294 Online
Bytes | Software Development & Data Engineering Community
Create 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 3590
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_SOFTWARE
machineSoftwareID 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, 124 views)
File Type: zip 2.zip (48.9 KB, 128 views)
File Type: zip 3.zip (17.9 KB, 116 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
Rabbit
12,516 Recognized Expert Moderator MVP
I don't see anything explicitly wrong with the code. What's the problem exactly? What's not working the way it should or what is it doing that it shouldn't be doing?
Nov 17 '07 #11
gcoaster
117 New Member
The problem is here somewhere ( well at least i think! )

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "DELETE * FROM MACHINESOFTWARE WHERE MACHINESOFTWARE.client =Forms!machine!cboFullName AND " & _
  2.     " MACHINESOFTWARE.machineName =Forms!machine!machineName AND " & _
  3.     " MACHINESOFTWARE.title =Forms!MACHINEsoft!lstInstalled "
The error is this when cmdRemove is clicked

Here is what pops up

| Enter Parameter Value |
[ Forms!MACHINEsoft!lstInstalled ]
Nov 17 '07 #12
Rabbit
12,516 Recognized Expert Moderator MVP
That error usually means you misspelled something or referenced the control incorrectly. If the control's on a subform, then the syntax is a bit different. Also, the form needs to be opened.
Nov 18 '07 #13
gcoaster
117 New Member
That error usually means you misspelled something or referenced the control incorrectly. If the control's on a subform, then the syntax is a bit different. Also, the form needs to be opened.
Fixed it Rabbit, Thank you! you where right..
Nov 21 '07 #14
Rabbit
12,516 Recognized Expert Moderator MVP
Not a problem, good luck.
Nov 21 '07 #15

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

Similar topics

0
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...
12
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...
10
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...
9
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...
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,...
1
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
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,...
0
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
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
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 ...

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.