PDA

View Full Version : Listbox Iteration and TextBox Issue



technocraze
12-13-2006, 07:17 AM
Hi, I am new breed to VB environment using MS Acess and presently in learning phase. It would be very appreciated if any expertise could guide me on my following queries.

1) Display the corresponding values selcted from the Listbox and display it in the textbox. Iterate through the listbox and display the values. But when i bound the textbox to the control source i encountered this error. I have set the foucs for both control but doesnt seem to be working

Error msg: Update or CancelUpdate without using Edit or AddNew

AfterUpdate event

Dim rs as DAO.RecordSet
set rs = Me.RecordSetClone
rs.FindFirst[Studentid] & Str
Me.Bookmark = rs.Bookmark
ListBox.SetFocus
TextBox.SetFocus

2) Iterate through the list using foreach loop in a Mutli-Select listbox environment(Single, Extended). Select a few values. I have assigned a variable for the listbox and use it in my sqlQuery under the where condition. What i want to achieve is using the selected values from the multilistbox with the where clause. where subject = (the selected values from the multi-listbox)

Click_command

Dim subject as Variant
Iterate through the listbox (Foreach loop)
Query the listbox (SqlQuery) where condition (values from the listbox)

Thanks in Advance!

OBP
12-13-2006, 10:14 AM
Why are you trying to do the first part in VBA when you can do it on the form and then use the VBA to iterate through the selected items in the list box to add them to your SQL?

technocraze
12-14-2006, 08:05 AM
MAy I knw hw to iterate through the listbox and select the values. I am using something like this. Iam nt too sure as hw to use RecordSet and its properties. I am using MS Acess in vb environment

Dim item As Variant
Dim sqlStat as String
Dim studentId As string

Assign studenId to ListBox

foreach item in Listbox1.Selected
sqlStat = Update [TableName] set [field1, field2, field3] values [TextBoxes control] where studentId = Listbox1 control (selected value of listbox)

mud2
12-15-2006, 09:26 PM
Check my entry under "how to extract a field from a table..."

Cosmos75
12-15-2006, 10:56 PM
MAy I knw hw to iterate through the listbox and select the values. I am using something like this. Iam nt too sure as hw to use RecordSet and its properties. I am using MS Acess in vb environment

Dim item As Variant
Dim sqlStat as String
Dim studentId As string

Assign studenId to ListBox

foreach item in Listbox1.Selected
sqlStat = Update [TableName] set [field1, field2, field3] values [TextBoxes control] where studentId = Listbox1 control (selected value of listbox)2nd time you've asked.... (http://vbaexpress.com/forum/showthread.php?t=10585) (my answer to the iteration part (http://vbaexpress.com/forum/showpost.php?p=82721&postcount=2))