473,379 Members | 1,253 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Update selected items in a List Box

Hi All...

I have an unbound form.
The form includes:
A ComboBox (from table Callers) "cmbTMCode "
A ListBox MultiSelect=Extended, (from table Leads) "lstSelect"
A CommandButton "btnAssign"

I would like to
1) Select a value from "cmbTMCode"
2) Select multiple records from "lstSelect"
3) Click "btnAssign"
4) Update the TeleMCode field in the "Leads" table with the value
in "cmbTMCode" for the selected records in "lstSelect"
Private Sub btnAssign_Click()
Dim db As Database
Dim rec As Recordset
Dim varSelected As Variant
Dim strSQL As String

Set db = CurrentDb()
Set rec = db.OpenRecordset("Leads")

For Each varSelected In Me!lstSelect.ItemsSelected
strSQL = ""
strSQL = strSQL & " Update leads SET TMCode = " & Me.cmbTMCode
strSQL = strSQL & " WHERE ID = " & Me!lstSelect.ItemData(varSelected)
CurrentDb.Execute strSQL ..Access complains here << Run-Time error
'3061': Too few parameters. Expected 1.>>
Next varSelected

Set db = Nothing ' Clear db...
msgbox ("This data is now in your table..")
End Sub

Any Help?
EiEiO

Oct 15 '06 #1
6 8653
How to debug your code....
I would stick a debug.print in the loop to see if any values are being
produced and to see what sql is created
wack the sql into a query and run it. The error message should be clearer.

For Each varSelected In Me!lstSelect.ItemsSelected
strSQL = ""
strSQL = strSQL & " Update leads SET TMCode = " & Me.cmbTMCode
strSQL = strSQL & " WHERE ID = " & Me!lstSelect.ItemData(varSelected)
'Add this line of code....
debug.print "List Value= " & Me!lstSelect.ItemsSelected & " MySQL= " &
strSQL
CurrentDb.Execute strSQL ..Access complains here << Run-Time error
'3061': Too few parameters. Expected 1.>>
Next varSelected

"EiEiO" <de****@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
Hi All...

I have an unbound form.
The form includes:
A ComboBox (from table Callers) "cmbTMCode "
A ListBox MultiSelect=Extended, (from table Leads) "lstSelect"
A CommandButton "btnAssign"

I would like to
1) Select a value from "cmbTMCode"
2) Select multiple records from "lstSelect"
3) Click "btnAssign"
4) Update the TeleMCode field in the "Leads" table with the value
in "cmbTMCode" for the selected records in "lstSelect"
Private Sub btnAssign_Click()
Dim db As Database
Dim rec As Recordset
Dim varSelected As Variant
Dim strSQL As String

Set db = CurrentDb()
Set rec = db.OpenRecordset("Leads")

For Each varSelected In Me!lstSelect.ItemsSelected
strSQL = ""
strSQL = strSQL & " Update leads SET TMCode = " & Me.cmbTMCode
strSQL = strSQL & " WHERE ID = " & Me!lstSelect.ItemData(varSelected)
CurrentDb.Execute strSQL ..Access complains here << Run-Time error
'3061': Too few parameters. Expected 1.>>
Next varSelected

Set db = Nothing ' Clear db...
msgbox ("This data is now in your table..")
End Sub

Any Help?
EiEiO

Oct 15 '06 #2
I think you must add a ; at the end of the sql statement
strSQL = ""
strSQL = strSQL & " Update leads SET TMCode = " & Me.cmbTMCode
strSQL = strSQL & " WHERE ID = " & Me!lstSelect.ItemData(varSelected) &
";"

Oct 15 '06 #3
On the contrary, the semi colon is optional.

"Svetlana" <Ac**********@yahoo.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>I think you must add a ; at the end of the sql statement
strSQL = ""
strSQL = strSQL & " Update leads SET TMCode = " & Me.cmbTMCode
strSQL = strSQL & " WHERE ID = " & Me!lstSelect.ItemData(varSelected) &
";"

Oct 15 '06 #4
Ive added the line <<Debug.Print "List Value= " &
Me!lstSelect.ItemsSelected & " MySQL= " & strSQL >>as you suggested .
Access complains <<Tun-time error 450: Wrong number of arguments or
invalid property assignment
EiEiO

Oct 15 '06 #5
The code for the listitem is correct, so it could the the combobox bit
Me.cmbTMCode (is ir a string value ?)
If the combo or list value is a string, you will need to wrap the SQL in
'single' quotes as below
strSQL = "Update leads SET TMCode = '" & Me.cmbTMCode & "' WHERE ID = '" &
Me!lstSelect.ItemData(varSelected) & "'"


"EiEiO" <de****@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
Ive added the line <<Debug.Print "List Value= " &
Me!lstSelect.ItemsSelected & " MySQL= " & strSQL >>as you suggested .
Access complains <<Tun-time error 450: Wrong number of arguments or
invalid property assignment
EiEiO

Oct 15 '06 #6
EiEiO wrote:
Hi All...

I have an unbound form.
The form includes:
A ComboBox (from table Callers) "cmbTMCode "
A ListBox MultiSelect=Extended, (from table Leads) "lstSelect"
A CommandButton "btnAssign"

I would like to
1) Select a value from "cmbTMCode"
2) Select multiple records from "lstSelect"
3) Click "btnAssign"
4) Update the TeleMCode field in the "Leads" table with the value
in "cmbTMCode" for the selected records in "lstSelect"
Private Sub btnAssign_Click()
Dim db As Database
Dim rec As Recordset
Dim varSelected As Variant
Dim strSQL As String

Set db = CurrentDb()
Set rec = db.OpenRecordset("Leads")

For Each varSelected In Me!lstSelect.ItemsSelected
strSQL = ""
strSQL = strSQL & " Update leads SET TMCode = " & Me.cmbTMCode
strSQL = strSQL & " WHERE ID = " & Me!lstSelect.ItemData(varSelected)
CurrentDb.Execute strSQL ..Access complains here << Run-Time error
'3061': Too few parameters. Expected 1.>>
Next varSelected

Set db = Nothing ' Clear db...
msgbox ("This data is now in your table..")
End Sub

Any Help?
EiEiO
I might make reference to the value in the listbox like this
For Each varItem In Me.ListBox.ItemsSelected
lngID = Me.ListBox.Column(0, varItem)
msgbox lngID
Next

And I don't know if your code value is char or numeric. If char,
surround by quotes.

And if worse got to worse, I'd do a
Debug.Print strSQL
and take/cut that value printed in the debug window and attempt to
execute the SQL by opening a new query in design mode, add no tables,
click on View from the menu, select SQL, and paste the SQL string to the
window.
Oct 15 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old...
3
by: Stanley J Mroczek | last post by:
I have tried this with no luck. What i want is to show the selected item on the first post. the selected item is NY but the first in the list shows as selected. If Page.IsPostBack = False Then...
8
by: Vipin Kedia | last post by:
Hi I have written a code for showing the list boxes as selected using a Listitem and the selected property of the items. Now I have 2 list boxes in my page. But it shows only the selected values...
1
by: Aaron Prohaska | last post by:
I'm having the problem with this drop down list on postback. For some reason both the ListItems get selected when I change the selected item. Using the code below I'm building the drop down list in...
3
by: Stephen Adam | last post by:
Hi there, I'm sure i'm missing something really simple here, all i want to do is get the value of the selected item in a list box. Even after much fiddling about last night I still could not get...
11
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to...
0
by: Brian Henry | last post by:
Since no one else knew how to do this I sat here all morning experimenting with this and this is what I came up with... Its an example of how to get a list of items back from a virtual mode list...
2
by: Hitesh | last post by:
I have a listbox and the values get selected (highlighted) from code. I can highlight the corresponding list box items, but they do not show in the listbox I have to scroll through the list box to...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
3
by: =?Utf-8?B?SmFtZXMgUGFnZQ==?= | last post by:
I've a multiview with 3 views. on view 2 the user is presented with a check box list (items from database) at view 3 the user can review their selections and, either post to the database or go back...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.