A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

MultiSelect Listbox



 
 
Thread Tools Display Modes
  #1  
Old October 20th, 2009, 09:22 AM posted to microsoft.public.access.forms
Letica via AccessMonster.com
external usenet poster
 
Posts: 4
Default MultiSelect Listbox

I've a MultiSelect listbox (named : lbLocation)in my form (named:101 :
Inventories). After selecting the items in this listbox and click the
RunQuery command button, the following code will be executed :

Private Sub RunQuery_Click()
Dim frm As Form, ctl As Control
Dim varLoc As Variant
Dim strSQL As String
Set frm = Forms![101 : Inventories]
Set ctl = frm!lbLocation
strSQL = "Select * from [101 : Inventories] where Location="
For Each varLoc In ctl.ItemsSelected
strSQL = strSQL & "'" & ctl.ItemData(varLoc) & "' OR Location="
Next varLoc
strSQL = Left$(strSQL, Len(strSQL) - 13)
DoCmd.RunSQL strSQL
End Sub

But, it stops at "DoCmd.RunSQL strSQL" and prompts following error message :
Run-time error ‘2342’
A RunSQL action requires an argument consisting of an SQL statement.

Please help..

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200910/1

  #2  
Old October 20th, 2009, 01:27 PM posted to microsoft.public.access.forms
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default MultiSelect Listbox

As the error is trying to tell you, you cannot use RunSQL with a Select
query: it only works with Action queries (Update, Insert Into, Delete)

What are you hoping will happen when you run the Select query?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Letica via AccessMonster.com" u48292@uwe wrote in message
news:9ddd8ac633b2c@uwe...
I've a MultiSelect listbox (named : lbLocation)in my form (named:101 :
Inventories). After selecting the items in this listbox and click the
RunQuery command button, the following code will be executed :

Private Sub RunQuery_Click()
Dim frm As Form, ctl As Control
Dim varLoc As Variant
Dim strSQL As String
Set frm = Forms![101 : Inventories]
Set ctl = frm!lbLocation
strSQL = "Select * from [101 : Inventories] where Location="
For Each varLoc In ctl.ItemsSelected
strSQL = strSQL & "'" & ctl.ItemData(varLoc) & "' OR Location="
Next varLoc
strSQL = Left$(strSQL, Len(strSQL) - 13)
DoCmd.RunSQL strSQL
End Sub

But, it stops at "DoCmd.RunSQL strSQL" and prompts following error message
:
Run-time error '2342'
A RunSQL action requires an argument consisting of an SQL statement.

Please help..

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200910/1



  #3  
Old October 21st, 2009, 02:17 AM posted to microsoft.public.access.forms
Letica via AccessMonster.com
external usenet poster
 
Posts: 4
Default MultiSelect Listbox

Hi,

It will list out the inventories in the location/s selected by the user in
the MultiSelect listbox.

Douglas J. Steele wrote:
As the error is trying to tell you, you cannot use RunSQL with a Select
query: it only works with Action queries (Update, Insert Into, Delete)

What are you hoping will happen when you run the Select query?

I've a MultiSelect listbox (named : lbLocation)in my form (named:101 :
Inventories). After selecting the items in this listbox and click the

[quoted text clipped - 20 lines]

Please help..


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200910/1

  #4  
Old October 21st, 2009, 06:41 PM posted to microsoft.public.access.forms
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default MultiSelect Listbox

List where? Are you hoping to display a recordset? It's generally frowned
upon to allow users to interact directly with tables or queries: you should
always use a form.

If you don't care about that advice, you can always create a query (look up
CreateQueryDef) with the SQL you've generated and execute it.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Letica via AccessMonster.com" u48292@uwe wrote in message
news:9de667d1b2f5e@uwe...
Hi,

It will list out the inventories in the location/s selected by the user in
the MultiSelect listbox.

Douglas J. Steele wrote:
As the error is trying to tell you, you cannot use RunSQL with a Select
query: it only works with Action queries (Update, Insert Into, Delete)

What are you hoping will happen when you run the Select query?

I've a MultiSelect listbox (named : lbLocation)in my form (named:101 :
Inventories). After selecting the items in this listbox and click the

[quoted text clipped - 20 lines]

Please help..


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200910/1



  #5  
Old October 21st, 2009, 11:26 PM posted to microsoft.public.access.forms
Letica via AccessMonster.com
external usenet poster
 
Posts: 4
Default MultiSelect Listbox

The users do not interact directly with tables or queries.

The MultiSelect listbox in the form. User can select the locations in this
box. After selecting the select items and clicking the "RunQuery" command
button, the code will be executed, the query (named: 101 Inventories) will
run and result will be displayed.



Douglas J. Steele wrote:
List where? Are you hoping to display a recordset? It's generally frowned
upon to allow users to interact directly with tables or queries: you should
always use a form.

If you don't care about that advice, you can always create a query (look up
CreateQueryDef) with the SQL you've generated and execute it.

Hi,

[quoted text clipped - 11 lines]

Please help..


--
Message posted via http://www.accessmonster.com

  #6  
Old October 22nd, 2009, 12:07 PM posted to microsoft.public.access.forms
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default MultiSelect Listbox

Displayed for what purpose, though? If all you care about is a read-only
list, why not use the query as the RecordSource for a report? Then, they
can print it if they want to.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Letica via AccessMonster.com" u48292@uwe wrote in message
news:9df17ae89b671@uwe...
The users do not interact directly with tables or queries.

The MultiSelect listbox in the form. User can select the locations in
this
box. After selecting the select items and clicking the "RunQuery"
command
button, the code will be executed, the query (named: 101 Inventories) will
run and result will be displayed.



Douglas J. Steele wrote:
List where? Are you hoping to display a recordset? It's generally frowned
upon to allow users to interact directly with tables or queries: you
should
always use a form.

If you don't care about that advice, you can always create a query (look
up
CreateQueryDef) with the SQL you've generated and execute it.

Hi,

[quoted text clipped - 11 lines]

Please help..


--
Message posted via http://www.accessmonster.com



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:13 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.