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

how to give a value of textbox in query

hi guys,
I have a combobox and i want to use that value in query
suppose I have form in that i have textbox and combo box
and button. And I have code like this in button onclick event.

Code:

Expand|Select|Wrap|Line Numbers
  1. If Combo2.Value = "Department" Then
  2. strSQL = "select distinct * from Laptops where Department like '*" & txtKeyword.Value & "*'  "
  3. Me.SubLaptops.Controls.Item("txtQuantityOrdered") = DSum("[quantity ordered]", "Laptops", "[Department] like '*" & txtKeyword.Value & "*'")

but i want make query of this code how can i do?
Expand|Select|Wrap|Line Numbers
  1. DSum("[quantity ordered]", "Laptops", "[Department] like '*" & txtKeyword.Value & "*'")
i want to pass the value of textbox in query.
i tried like this

Expand|Select|Wrap|Line Numbers
  1. select sum[quantity order] from laptop
  2. where [comboox value] = "whatever User Select the value from combobox " & [textbox value] =" whatever user type"

Thanks a lot.
Jun 2 '11 #1
2 2498
Mihail
759 512MB
Create a PUBLIC function:
Expand|Select|Wrap|Line Numbers
  1. Public Function WhereClause() as String
  2.     WhereClause = YourForm.YourComboBox.Text & YourForm.YoutTextBox.Text
  3. End Function
In the "Criteria" row of your query write: WhereClause()

Of course the name of the function can be anything else.

I am sure that exist an easy way but I am not skilled enough in Acces VBA.

Good luck !
Jun 3 '11 #2
NeoPa
32,556 Expert Mod 16PB
That is one good answer. Another is to refer to the item specifically within your SQL (See Referring to Items on a Sub-Form for more on this) :

Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT DISTINCT * " & _
  2.          "FROM Laptops " & _
  3.          "WHERE "Department Like '*" & Forms("Formname").txtKeyword.Value & "*')"
Jun 3 '11 #3

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

Similar topics

1
by: Chuck | last post by:
I have a query that uses the query with the critera set to . We I run the query the msgbox pops up asking for the name information to be entered, but on the top (blue background) of the message box...
0
by: Patrick De Ridder | last post by:
I posted this query before, but am not seeing it listed. If I enter a return in a text entered into a textBox, the rest of the text gets lost after a write textBox.Text and a read textBox.Text....
3
by: VB Programmer | last post by:
In my ASPX page how do I get the .text value of a textbox that is in the ItemTemplate of a datalist (using HTML)? The textbox contains the quantity for a shopping cart item. The textbox is...
2
by: dath | last post by:
Hi, Searched the forum and found a lot on passing form input to aquery but not the other way around. Here is the situation: I have a timesheet form based on a subform query that asks the...
14
by: sudheerk | last post by:
please give me a query for already existing name in the data base using mysql
10
by: arial | last post by:
Hi all, I need some help on retrive the value from query string. I have two web forms. One has the datagridview which displays the data from database. On one of the column I made a hyperlink to...
11
by: prisesh26 | last post by:
hi, iam passing a name "sun & moon" in my query string as a parameter. but when i receive it through request.getParameter iam getting only sun. rest are getting ignored due to & symbol. how...
5
by: ellie | last post by:
Hello I have a table (MainTable) with the fields (PK)ID (cbo)from_dept document_date reference_number last_reference I have a query on the first 4 fields that is sorted to give the last...
7
by: Ken Jones | last post by:
Can this conversion be done using Microsoft Access? If so how? Could this be done using TRANSFORM and PIVOT SQL statements? The Old Format columns are NO and URL The New Format...
3
by: JenniferM | last post by:
Annnnnd I'm back again, with a new problem, of course. I've got a table, TblKneeExamInfo, which corresponds to a form, FrmKneeExamInfo. In it, there is a section where I need to input patient...
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...
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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.