Select Fields For Query

Sep 15, 2006

I've made a form with list boxes on, the user's selections from which are taken as parameters for a query, created by VBA code.

I want to add a final list box to the form from which the user can select which of the available fields they want to see in the query output (i.e. has the same effect as checking/unchecking the "Show" checkbox for each field on the standard query design grid).

I have written the following code to try and do this, but it isn't working. I'm very new to VBA and wonder if anyone can help me out by showing me what's wrong?


'Build Field List
If Me!lstFieldList.ItemsSelected.Count > 0 Then
For Each varItem In Me!lstFieldList.ItemsSelected
strFieldList = strFieldList & "[" & Me!lstFieldList.ItemData(varItem) & "], "
Next varItem
strFieldList = Left(strCriteria, Len(strCriteria) - 2)
Else
strFieldList = "'*'"
End If

'Create Query String
strSQL = "SELECT Centres." & strFieldList & " " & FROM Centres " & _
"Where " & strCriteria & _
" And " & strCriteriaCtr & strSortOrder & ";"


Running the above gives an error, and the section under "'Create Query String" is highlighted in debug mode so I guess the error must lie there? Either that, or the earlier part where strFieldList is being create is generating something which strSQL cannot interpret.

Many thanks in advance if you can help me.

Gary

View Replies


ADVERTISEMENT

Conditionally Select Query Fields

May 10, 2007

Is there a way to select a query field based on conditions? There is a table at work that I need to use for my reporting in which the field names are the months of the year. Since my report is monthly for that specific month only, I have to change my field in the query every single month. I would like to be able to put in some type of code that will automatically select the proper month field.

Is this possible?

Thanks! :)

View 2 Replies View Related

Query With Parameter To Select Certain Fields

Jan 12, 2008

Hi, I need help in creating a parameterized query.

I need to show only certain fields depending on the value of the parameters.
For example, I have a table with fields: ID, Name, Phone Number, Address, DOB.
The parameter can only be value of A, B or C.
If the user input A as the parameter in the query, only field ID, and Name will be shown
If the user input B as the parameter in the query, field ID, Name and Phone Number will be shown.
etc.

Is there any way to do this, rather than to separate the query into 3 queries for each of the parameters? Thank you.

View 1 Replies View Related

Form To Select Fields For Query

Sep 14, 2006

I have written code to write a query with parameters set from selections made in a multiselect list box on a form.

I now want to add a check box for possible fields to include in the query and put these on the bottom of my form to allow users to select which fields they want to be displayed in the query result.

Can anyone advise how I can do this?

Many thanks,

Gary

View 1 Replies View Related

Adding Static Fields To A Select Query

Nov 15, 2005

I wish to add a static field to a select query i.e a field that does not exist within a table.

Does anyone know how I can do this?

Thanks

View 4 Replies View Related

Using Checkboxes To Select Multiple Fields In An Iif Query

Dec 1, 2005

Hi all,


Firstly, I'm an ex-fulltime access developer who has found himself doing access work again 6 years later; I can't actually believe how much I've forgotten :s

Anyway, I've done a search and havn't found anything that can help me so wondered if anyone could give some advice.

I have an access form with 3 combo boxes and a checkbox next to each of them. these are accessed using a query with 3 iif statements in it stating; (iif checkbox is null, "*", combo_box_value). the whole query looks like this

SELECT Customers.*
FROM Customers
WHERE (((Customers.Partner)=IIf(Forms!frm_rpt_main!check _partner Is Null,"*",Forms!frm_rpt_main!partner)) AND ((Customers.[Type Business])=IIf(Forms!frm_rpt_main!check_type Is Null,"*",Forms!frm_rpt_main!type)) AND ((Customers.[Year End Month])=IIf(Forms!frm_rpt_main!check_month Is Null,"*",Forms!frm_rpt_main!month)));

However, the query only seems to want to pull data from all 3 combo boxes

My issue is that if a checkbox is not ticked, I want the values to be ignored for all 3 combo's.

I've attached a copy of the mdb file as my description probably doesnt make any sense, the specific query is "qry_select_month_partner_type_wname_frm_rpt"


Thanking you all in advance for your help!

Younger

View 6 Replies View Related

Select All Query Fields For Main Form?

Sep 13, 2013

I have a table with about 3800 records and about 150 fields. It also has 4 tables with related data that each have only one field. I am going to create a query to base my from from. Should I just take the star * and get all the fields for each table or should i manually specify them. There are only about 5 fields out of the 150 that I dont need and I need to see the rest.

View 13 Replies View Related

More Than 255 Fields Management In A Select Query Of Access 2000

Apr 26, 2007

Dear sir/madam

I have two tables linked together with one-one relationship with primary key.
The form has been created using a select query using these two tables. total fields at present is 253(table1=25 fields, Table2=228 fields Total = 253 fields)

Now my problem is I have to add 20 fields more to the above. so the total fields now is 273 fields but it is not accepting and giving the error as "Too many keys defined 3190".

how to solve these problem

Thanks in anticipation
L.Ranganathan

View 14 Replies View Related

Select Query To Find Empty Date Fields

Jan 26, 2008

I am trying to create a select query on "ApprovedDate" where no approval is recorded. IsNull returns an expected type mismatch. Any ideas?
Regards:confused:

View 2 Replies View Related

Queries :: Form To Select Which Fields Show In Query

Oct 8, 2013

I want to create form with 10 checkbox, each checkbox is linked to a field "name, Address, TelephoneNumber, BuissinessName" I would like to know if it is possible for the user to check the box and then the field will show in query. if only name is check then only name will show in the query.

I have tried using [Forms]![Formname]![CheckboxName] as criteria but this didn't work it when I had more then one checkbox and when the one check box was not checked nothing showed in the forms.

View 5 Replies View Related

Queries :: Allowing Users To Select Multiple Table Fields As Query Criteria

Apr 22, 2013

I am fairly new to Access and I would like to create a form to allow users to create their own query. I would like to allow users to select multiple fields (perhaps with checkboxes?) from all possible fields in a table to return either all data from that field or narrow their search by inputting certain criteria or choosing from a drop down into a text box. Is this possible in Access and any detailed specifics on how to achieve this?

View 3 Replies View Related

Combo Box Select With TWO Fields

Jan 28, 2005

I have a database of customers, and I'd like to be able to pull up a specific record on a form. Currently the only way I know how to do this is by ID number (the primary key). I'd like to be able to search by their last name and first name (of course we have people with the same last name), so for instance I'd like to be able to input "Smith" and then have a list of all the smiths to choose from. Is there a way to do this? Thank you!

View 2 Replies View Related

Import Problem Can't Select Different Fields

Nov 15, 2005

I am having a problem with Access, when I import a text file everything goes fine until I get to the screen after selecting to import into a new table. The one where you can rename the fields and select the data types and choose to skip the field. Here you should be able to select any of the fields and make changes, well when I select another field nothing happens it does not change to that field. See the attached image where field3 is picked but the field options still had field1.

Anyone else come across this or have any suggestions for fixing it? I guess I could reinstall Access but it's an office computer and would require getting our IT staff to do it since I don't have access to the Access install files.

The file will import fine if you go to finish but it loses data because the fields are not set properly for the data being imported, and I could always create a table first but sometimes it's just easier to do it at load time.

Thanks for any help,

View 2 Replies View Related

Select Latest Date From 4 Fields....

Jul 21, 2005

I have a simple table in Access 2003:

Case# (numeric)
CaseOpen (Date)
CaseClose (Date)
Item# (numeric)
ItemOpen (Date)
ItemClose (Date)

Some of the date fields may be null; If null then that date may NOT be selected

I am trying to write a query that returns:

Case#
Item#
Only the most recent date in any of the four date fields
The heading that matches the selected date field

ie:
Case# = 251
Item# = 4756
Most Recent Date = 7/8/2005
Matching Heading = "ItemOpen"

I have been searching and reading for two days-
Help, please?

TIA

View 1 Replies View Related

Select DISTINCT - Selecting Two Fields

Aug 9, 2005

Hi

I am trying to use a query to populate a combo box. works fine as I am using one table. I want to select DISTINCT records which works. However i need the ID of that record in the select statement. Anyone know how to select two things in a select distinct query??

Select DISTINCT tbl_Aplaws.Level2 FROM tbl_Aplaws WHERE tbl_Aplaws.Level1 = 'Business' ORDER BY tbl_Aplaws.Level2;

this works. but i need to select the tbl_Aplaws.AplawID as well. throws errors

View 1 Replies View Related

Modules & VBA :: Select All Fields That Contain Textbox Value

Oct 20, 2014

I'd like user to input what he's looking for in a textbox and then to filter all the records that contain that word.

values could be like rome, paris, belgrade

When user inputs rome, all fields containing rome should appear

tblTest like '%rome%'
should this work

tblTest like '" & Me.txtTest & "'
tblTest like '%" & Me.txtTest & "%' "

these give filters in report respectively :
tblTest like 'rome'
tblTest like '%rome%'

I might have something else wrong, but i don't get the desired results. No records are displayed...

View 4 Replies View Related

Creating Non-Calculated Fields In Select Queries

Nov 14, 2005

Hi All!

I am trying to create an updateable non-calculated field in a select query. Specifically, I want to create a Yes/No data type called "Fail".

This is a multiple-user application so I can't solve the problem by using append and delete queries to modify records in a table.

This has turned into a much stickier problem than I anticipated. I would appreciate any insight or advice you have.

View 2 Replies View Related

Join Two Fields In Select Statement Results

Apr 12, 2006

I'm sure this is easy to do, but I'm not sure how to word my search criteria when trying to look for a solution.


Let's say that I have 2 fields in MyTable: FirstName, LastName.

I've been trying to use the following query, but obviously it does not work:
Select (FirstName + ' ' + LastName) as MyName from MyTable.

I would like to have the following data returned to me in the following format:
John Doe
Jane Doe
Jim Doe
Jill Doe

Thanks,
CRhodus

View 1 Replies View Related

Select From Drop Down To Populate Three Fields In A Table?

Nov 6, 2012

I would like to be able to select a value from a drop-down and by doing so be able to populate three fields in a table.

View 12 Replies View Related

Select Fields Of Table To Use When Printing Mailing Labels

Jan 2, 2008

I have a table that contains a lot of different information regarding to mailing.

There are columns for Name, Address, Address2, Address 3, City, State, Zip, Country, Base Name, etc.

Some units will only required parts of the above information. I'm using the Name as an identifier in the DB only and Address is the beginning of content that I want to use.

My issue stems out of the fact that the City, State, and Country are not always required but the Base Name, may be used in lieu of the City.

I was looking at making checkboxes next to each of the columns on the form on the field and then using those checkboxes somehow to create a report for Mailing Labels.

I'm just not sure how to set this up.

View 5 Replies View Related

Forms :: How To Get Two Different Fields To Autopopulate When Select A Choice From Combobox

Jan 10, 2014

I am trying to get two different fields to autopopulate when I select a choice from a combo-box on my form.

I have a form called IncomeRcvdFrom, which takes its fields from the table "IncomeRcvd"

In the form, I have three fields that need to relate to each other and auto populate.

The first field is called "IncmType", which comes from a different table called "CategoriesList". There is another field called "IncmDescr" which also comes from the same table. The third field, called "Category" is a list box in that table that comes from another table called "CatType".

All three of these fields also are list boxes in the table "IncomeRcvd", where the source of these fields come from the "CategoriesList" and the "CatType" tables.

What I am trying to accomplish is so when someone selects an Account, or "IncmType", it auto populates the "IncmDescr" field, as well as the "CatType" field on the form.

So far, I have gotten the Account or IncmType and the IncmDescr fields to autopopulate each other, but the Category field either says "Name?", or I get the "type mismatch expression" error message. I also accidentally got the field to work one time, but it would only display the ID Key field and not the actual wording in the rows (i.e. Misc. Payment, Royalty, Rebilling, etc.)

I have checked my relationships, my control sources, and still can't get it to work.

View 7 Replies View Related

Queries :: Select Distinct Field And Showing Other Fields?

Jun 4, 2013

How to query Select Distinct field + showing other fields? E.g.:

Code:
SELECT DISTINCTROW assetMovementTable.assetNo, assetMovementTable.moveCode, assetMovementTable.compCode, assetMovementTable.compCodeDesc, assetMovementTable.assetDesc, assetMovementTable.equipType, assetMovementTable.equipManufacturer, assetMovementTable.equipModel, assetMovementTable.constYear, assetMovementTable.plateNo
FROM assetMovementTable

[Code] ......

View 7 Replies View Related

Queries :: Conditionally Choose Fields In SELECT Clause

Feb 28, 2014

I have a table with 2 fields:

CODEDATE (text)
DATE1 (date)(dd/mm/yyyy)

RECORDS SAMPLE:

Code:
-------------------------------------
CODEDATE DATE1
-------------------------------------
TT-10/10/2013 01/01/2012
ASDFDFDF 01/02/2013
RR-18/06/2012 05/08/2012
------------------------------------

I need to extract the date from CODEDATE field if the "-" character exist in or from DATE1 if the character "-" is not present in the CODEDATE field, then filter the query on the date found.

I wrote that:

Code:
SELECT IIf(Mid([CODEDATE],3,1)='-',Mid([CODEDATE],4,10),[DATE1]) AS DateFound
FROM MyTable
WHERE (IIf(Mid([CODEDATE],3,1)='-',Mid([CODEDATE],4,10),[DATE1])
Between 1/1/2013 And 31/12/2013)

The query above extra extract some records without sense for me, I tried many other syntax without success.

View 12 Replies View Related

Selection In Combo Box That Auto Select Two Other Fields In Same Row Of Table

Aug 12, 2013

I have a table called Auction, it has three fields, seller, iid, and start_time.

I made a combo box on a forum and in the I have a query,

My question is, I have a few combo box, can I have a user select a seller, but it will automatically populate in the same row, the iid and start_time for this seller?

How do I do this, I can't have separate combo box and have user select for each seller, iid and start time because it wouldn't match it to that seller on the same row.

View 4 Replies View Related

Queries :: Select Query To Gather Results Of Other Select Queries

May 11, 2014

I'm fairly new to Access. 's various select queries containing useful and useless results. I want to create a select query that will pick out all the useful figures into a 1 row table that can then be pasted into Excel.

e.g Existing Select Query 1 returns 1 row showing Average Age, Average Price, Total rainfall
Existing Select Query 2 returns 1 row showing Average Weight, Average Salary, Total snowfall
Existing Select Query 3 returns *2* rows: It returns Distance from London, Hours daylight and population for Town A and Town B

I want a select query that returns 1 row showing (6 items):

Total rainfall, Total snowfall, Town A Distance from London, Town A Population, Town B Distance from London, Town B Population.

I've been able to handle getting Total rainfall and Total snowfall. But I cant figure out how to get Town A Distance from London, Town A Population, Town B Distance from London, Town B Population to appear in the same row of the same query results as Total rainfall, Total snowfall.

View 3 Replies View Related

Reports :: Use 1st Query To Populate Fields Then Use 2nd Query To Filter Fields

Apr 30, 2013

Any way in report that I have 2 reference queries just 1 is to populate all details and 2nd query to filter details and will be the final reporting information???

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved