473,322 Members | 1,566 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,322 software developers and data experts.

SQL query in OnClick subroutine of a listbox

I want to write an SQL query inside the Onclick event of a list which will allow me to populate another list based on the selected value.

So suppose the selected value is
Dim ID As Integer
ID = SourceList.Column(0) //This works fine btw

I want to be able to do something like this
Expand|Select|Wrap|Line Numbers
  1. DestinationList.Value(
  2. select field1,field2,field3
  3. from tablexyz
  4. where tablexyz.field1=ID
  5. )
The problem is:I don't know how to tell it to link the destination list to my select query
Sep 16 '08 #1
2 2893
NeoPa
32,556 Expert Mod 16PB
Not too far off Saratee.

Marseilles v Liverpool is just about to kick off, but when I can I will come back and look at giving some pointers.

As I say you're not too far off already. The SQL would need to be built up in a VBA string and the ListBox.RecordSource (not .Value) is what needs to be set.
Sep 16 '08 #2
NeoPa
32,556 Expert Mod 16PB
Something like :
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2. ...
  3. strSQL = "SELECT [Field1],[Field20,[Field3] " & _
  4.           "FROM [TableXYZ] " & _
  5.           "WHERE [Field1]=%ID"
  6. strSQL = Replace(strSQL, "%ID", Me.ID)
  7. DestinationList.RecordSource = strSQL
First you set up the variable strSQL with the SQL template (%ID is a placeholder), then you replace %ID with the actual value found on the form. This assumes Me.ID is a numeric value.
Sep 16 '08 #3

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

Similar topics

1
by: Johan Smidje | last post by:
Hi. I'm trying to locate one node in the following XML: <?xml version="1.0" encoding="utf-8" ?> <ROUTINES> <ROUTINE name="TA14"> <METHOD name="1"> <DEBET> <SUBROUTINE name="1401"></SUBROUTINE>...
1
by: Alan | last post by:
I created a Multi Select list box. I even got the code to create the SQL statement in a control called Item. Forms!Form1!Item Here is a sample of what appears in Item: Select Name, activity...
3
by: Sami | last post by:
Maybe I am going about this totally wrong.... What I have written is a query pulling SSN, Student-ID, LastName, FirstName, MiddleInitital from a table. Sort is so LastName, FirstName,...
7
by: Dave Hopper | last post by:
Hi I posted a question recently regarding problems I am having getting a value from a list box to use in a query. I got a lot of help, for which I thank you and it's nearly working! But I need...
4
by: carl.barrett | last post by:
Hi, I have a list box that displays 2 columns. Behind it sits a query with five columns. These are Column1 (DOB), column2 (a concatenated string of Surname Forname, Title), Column3 (Surname),...
1
by: Stephen D Cook | last post by:
I have a form with txtSN text box, btnShow button, and a subform. The form is bound to a Table. The button is bound to a lookup query. The query is bound to the text box. I want to be able to...
2
by: Chucara | last post by:
Hi, I'm trying to build a simple search in Access. I'll just give a simplified example, as I think I can solve the problem, if you can help me with this subproblem.. I have 2 listboxes -...
3
by: oopsatwork | last post by:
I'm trying to construct an XPath and it is giving me trouble. I have an XML that contains a "Routine". The routine contains "Steps". The steps have different types. Some types of steps have...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.