Queries :: Setting Field Width To Zero In Select Statement

Jun 11, 2015

I am building a form that uses list box selections on the form to make a temporary query and open the results in Excel.

It mostly works in just trying to make it more functional.

Currently the listbox that contains the first and last names of the personnel also has a unique shorttext 'number' as a primary key for the table (bad choice in my opinion but I didn't design the database I just have to work with it).

The short text primary key is hidden by an option given in the listbox wizard that let me set that field width to zero but still search on it. This is how I currently build the query's where clause when it involves names. I search the primary key.

I would like to update the names list box based upon which cities and locations are selected (both are multi-select).

Do I need to change how I make the "where" clause to use first and last names or an I use the same query and just hide the USER_ID

The query looks like this

Code:

SELECT DISTINCT t_asset_personnel.LAST_NAME, t_asset_personnel.FIRST_NAME, t_asset_personnel.USER_PHY_ID
FROM t_asset_personnel INNER JOIN t_asset_master ON t_asset_personnel.USER_PHY_ID = t_asset_master.ASSIGNED_TO
ORDER BY t_asset_personnel.LAST_NAME;

And the list box wizard hides USER_PHY_ID

By setting the width to zero

If I make my own query in the City_After_Update()

Can I do something like this

Code:

SELECT DISTINCT t_asset_personnel.LAST_NAME, t_asset_personnel.FIRST_NAME, t_asset_personnel.USER_PHY_ID
.fieldWidth(0)FROM t_asset_personnel INNER JOIN t_asset_master ON t_asset_personnel.USER_PHY_ID = t_asset_master.ASSIGNED_TO
WHERE [forms]![myform]![citylist].[itemsSelected]'obviously more code is needed here this is just for conceptual illustration
ORDER BY t_asset_personnel.LAST_NAME;

View Replies


ADVERTISEMENT

Queries :: Make Boolean (Yes / No) Field With SELECT INTO Sql Statement

Nov 28, 2013

I've been using a SELECT INTO statement to import data from a linked text file into a temporary table in Access. Something along the lines of :

SELECT [tblLink].[fld1] AS Field1,
[tblLink].[fld2] AS Field2,
[tblLink].[fld3] AS Field3
INTO [tblTemp]
FROM [tblLink]

(There's an INNER JOIN in there and some Nz / CLng functions but just want to keep it simple...)

Now - I've just realised I also need to create a couple of extra 'dummy' fields in my temporary table (for later on in the show) and I need them to be Yes/No format (will set them to False at first, then run some separate queries later to update them)

I tried this :

SELECT [tblLink].[fld1] AS Field1,
[tblLink].[fld2] AS Field2,
[tblLink].[fld3] AS Field3,
False AS Field4,
False AS Field5
INTO [tblTemp]
FROM [tblLink]

But this sets Field4 and Field5 as Number fields, with each record given a value of 0. What syntax is required in the SQL to make these fields Yes/No rather than Number?

View 4 Replies View Related

Queries :: Update Statement For A OUTER JOIN Select Statement

Feb 12, 2014

I have the following Select Statement:

SELECTTenant.ID, Tenant.[First Name], Tenant.[Last Name], Tenant.Address, Tenant.City, Tenant.State, Tenant.Zip, Tenant.[Home Phone], Tenant.[Cell Phone], Tenant.[Work Phone], Tenant.[Rented Unit],
Tenant.[Security Deposit], Tenant.[Move In], Tenant.[Move Out], Tenant.TenantID, Tenant.UnitID, Tenant.PropertyID, Tenant.OwnerID, Owner.Company, Owner.ID AS Expr1, Property.[Property Address],

[code]....

Now, I know that something in the UPDATE statement does not match my select statement.What should my Update Statement be, in order to update all the columns in the joined tables?

View 2 Replies View Related

Queries :: Select Statement To Max Value

Jul 12, 2013

I'm trying to do a select statement and put it in a variable which i can then output to a text box. How do I get the value into a variable? I can't seem to get my syntax right

This is what I currently have

Maxvalue = "SELECT MAX[Record Num]FROM Joblog"

View 2 Replies View Related

How To Format A Field In The Select Statement?

Sep 1, 2005

Hi!

I have a table called myTable and it contains two fields Year and Month. Both are type of integer.

Now in my select statement, I like to combine these two fields in to one and name it as period and it will have the format, for example 200501, 200502, ..., 200512. How can I do that in Access query statement?

I know how to do this in SQL Server 2000. That is:

Select Convert(varchar(4), [Year]) + right('00' + cast([Month] as varchar(2)), 2) as Period from myTable

How can I do that in Access Query statement?

Please advise.

Aijun.

View 4 Replies View Related

Queries :: Syntax Error Using IF In SELECT Statement

Jun 15, 2015

I'm trying to replace a null value with $0.00 for the second field in a query. My first try at the SELECT stmt did not contain any solution for a NULL value. The result was that it skipped the record. I need it to show 0.00 because the field is used in another calculated field.

My SQL:

SELECT tblRecovery.CustID, IF((Sum([tblRecovery.RecAmt]) IS NULL, 0.00, (Sum([tblRecovery.RecAmt]))) AS SumOfRecAmt
FROM tblRecovery
GROUP BY tblRecovery.CustID;

This returns : Syntax error (missing operator) in query expression 'IF(( etc.

After clicking "OK", access highlights AS in the statement. I'm not sure how to deal with the NULL value or fix the error?

View 6 Replies View Related

Queries :: Basic Delete Insert Select Statement

Nov 8, 2013

what is wrong with the following statements. I'm new to access SQl. This would work in ms sql.

Code:
DELETE from Table1
INSERT INTO Table1(email, productid, datecreated, datesend) values ('adf', 5, '10/10/2012','10/10/2012')
Select * from Table1

View 1 Replies View Related

Queries :: Select Statement To Return Specific Data From Another Column?

Nov 3, 2014

I was just wondering if this is a possibility to do in one query or if it has to be run from a number of different queries.

I am currently developing a database from scratch for work (with very little Access experience).

The current query I am trying to run, if linked to a number of tables with different information.

What I am trying to do primarily is link stock to a specific "Host Name", "Serial Number" and "Part Description".

In the "Host Name" there is for example - A1-TX10-10001, B1-TX2-10004, C1-TX-10004 - The latter part of the name is a unique identifier number. The first part is the compartment in which the "stock" sits. So you may have all three components (A1-TX1, B1-TX2, C1-TX3) linked to the same unique identifier (10001 for example)

The serial numbers naturally are different for every single one and of course the srial numbers are linked to the "Part Description" - which will read something like....."C1-TX3 Transmitter", "B1-TX2 Combiner" etc.....

When I run the query like this the Host Name (which is also linked to the unique identifier on its own (10001) it returns everything under "A1-TX1-10001"

What I would ideally like to do is write a statement so that if the "Part Description" contains "A1-TX1" it will only return rows that contain "A1-TX1" in the Host Name and the same for "B1-TX2" and "C1-TX3" in the same query.

If "Host Name" contains "A1-TX1" to return "Part Description" to contain "A1-TX1"

View 10 Replies View Related

Queries :: SELECT CASE Statement - Populate Each Unit With Assigned Category?

Apr 9, 2013

I have a simple SELECT CASE query. I'm not sure how the syntax goes and I want to learn about it.

In the attached file, if you click on "cohort table", you will see the categorization for each unit under "field1".

how will I be able to use a SELECT CASE statement in a query to populate each unit with assigned category?

View 1 Replies View Related

Queries :: Calculated Field - Top 50 Queries Setting Not Working

Sep 24, 2013

I have a query which returns a calculated percent. I have ordered that in descending order, and now want to see the top 50. So (In Access 2010) I entered 50 into 'Return'. But it returns all of the records!

Is this because pct is a calculated field? How can I correct this? The SQL seems to be correct.

Code:

SELECT TOP 50 HeciFail1.POHECI, HeciFail1.POQTY, HeciFail1.FAILQTY, IIf(Nz([FAILQTY])>0,Round(100/([POQTY]/[FAILQTY]),0),0) AS PCT
FROM HeciFail1
ORDER BY IIf(Nz([FAILQTY])>0,Round(100/([POQTY]/[FAILQTY]),0),0) DESC;

View 1 Replies View Related

Queries :: Setting Temp Var As The Field

Aug 16, 2013

I have a table [Employees] which has the following Fields

- TxtEmpID
- StrEmpName
- StrEmpPassword

Which I use for my login table with the following script:

If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[TxtEmpID]=" & Me.cboEmployee.Value) Then
TxtMyEmpID = Me.cboEmployee.Value

On my form the drop down to select the employee is

SELECT tblEmployees.[TxtEmpID], [tblEmployees].[strEmpName] FROM tblEmployees;

(Seemingly all this is based on the TxtEmpID)

When I create a Temporary Variable

[SetTempVar screen.activecontrol with the name SetUserID]

And then want to place the variable in a form or whatever else, I can only see the TxtEmpID. I would like to set the TempVar as the field StrEmpName.

View 11 Replies View Related

Queries :: Setting To Only Show Field In Simple Query Once

Sep 19, 2013

I have a simple query between two tables joined together by common fields. In my first table (Table 1 - tblLocations) I have information about a building i.e. Location Code, address and total sqft. . In my second table (Table 2 - tblAllocatedSpace), this contains details (Location Code, Room ID, SqFt assigned, etc.) of the space allocated in each building. The two tables are joined together when the “Location Code” in both table match.

In my query, I show the location detail from (Table 1 - tblLocations) and related records from (Table 2 - tblAllocatedSpace). My result looks like the following:

Location Code Sqft Address Assigned Sqft
106067 1,000 600 March Rd 10
106067 1,000 600 March Rd 15
106067 1,000 600 March Rd 12
106067 1,000 600 March Rd 20

The location code, Address and Sqft is rebated each time a space is assigned in (Table 2 – tblAllocatedSpace). When a build a report and need to sum the location Sqft, the number is multiplied by the number of related records in (Table 2 – tblAllocatedSpace). In this example by building total space is 4,000 sqft when I only it to show 1,000.

How do I set to only show the location code and sqft once?

View 1 Replies View Related

Queries :: IIF Statement Utilizing Yes / No Field

May 26, 2013

I am working on a hired plant database and want to limit the combo box on the hired form to only list items not on hire.I thought I could do this using the IssueDate and ReturnDate fields within a query with an IIf statement forcing the Yes/No field to choose Yes when there is a date in the IssueDate field and No when the ReturnDate field has a date entered.

View 14 Replies View Related

Queries :: If Statement As Selecting Field

Aug 27, 2013

I am having some trouble with an iif statement as selecting the field..I have two columns, one called [sdCounterpartyprice] and one called [bid]I want to select the [bid] if it's not equal to Null or 0, if it is equal to that then pick [sdCounterpartyprice]this doesn't work

Code:
CptyPrice: IIf ([bid] is null or = 0; [sdCounterpartyprice]; [bid])

View 3 Replies View Related

Queries :: Adjust Column Width To Best Fit Using VBA

Mar 20, 2013

How to adjust the column width of the fields to best fit in a Query using vba codes? Manually it can be done by selecting the Query - Click on More dropdown of the Reports section in the ribbon - Click on Column width - and select best fit as the option.I want this to happen by a vba code and not manually doing it everytime because the field length changes as it is a dynamically created Query.

View 3 Replies View Related

Importing From XML. Field Width Issue.

Apr 26, 2007

We are importing data from XML files manually to an access Database.
The imported tables are all text fields with field width 255.
Some text fields are too big and we end up loosing some records as import errors. Is there a way to let access generate an imported table with a text field that is longer than 255 character ?

View 5 Replies View Related

Setting Criteria Within A Select Query

Aug 23, 2005

I have set up a query to pull data from within a date range.

I have written an SQL Statement to amend the format of the date field:

Effective Date: IIf([Date_Effective_From]="00000000",Null,DateValue(Mid([Date_Effective_From],7,2) & "/" & Mid([Date_Effective_From],5,2) & "/" & Mid([Date_Effective_From],1,4)))

Within my criteria I have:

Between [Forms]![Benefits]![date1] And [Forms]![Benefits]![date2]

(Benefits being the form). If I enter date range 01/01/2005 to 01/05/2005 I receive all data from 01 January to 01 May - but including different years i.e 2002, 2003, 2004 etc.

Can anyone suggest anything I may have missed?

Thanks

View 1 Replies View Related

Queries :: Make A Nested If Then Statement In A Query Field

Apr 27, 2014

I'm trying to make a nested if then statement in a query field, and I can't figure out why I can't get my formula to work:

Volume: IIf([MethodCode]="K",[total]*12.54*0.026873,IIf([MethodCode]="S",([length]*[width]*[depth])/2,IIf([MethodCode]="M" And [Location]="SH",[total]*5.08*0.026873,IIf([MethodCode]="M" And [Location]="C",[total]*18.58*0.026873," "))))

I keep getting the "data type mismatch in criteria expression" error. If I separate out all the individual if then statements individually, they work. But if I connect them all as a nested if then it doesn't work.

View 6 Replies View Related

Queries :: SQL Where Statement Linked To Fields When Field Is Empty

May 23, 2013

I'm having trouble with using a where statement linked to fields when the field is empty. I need a way to say if field is null then 'do nothing'/'select all' else use the text from the box.

I have a form (ServicesRCSSearch) which has 3 combo boxes (Location1, Location2 and Location3). These fields are linked to a query. The button on the form generates the query.

My SQL for the query is currently:

Select Services.Key, Services.Location, Services_1.Location, Services_2.Location
From Services, Services_1, Services_2 (copies of the same table all left joined)

Where
((IIf(forms!ServicesRCSSearch!Location1 Is Null,"",services.Location=forms!ServicesRCSSearch! Location1))<>False)

And ((Services_1.Location)=IIf(forms!ServicesRCSSearch !Location2 Is Null,forms!ServicesRCSSearch!Location1,forms!Servi cesRCSSearch!Location2))

And ((Services_2.Location)=IIf(forms!ServicesRCSSearch !Location3 Is Null,forms!ServicesRCSSearch!Location1,forms!Servi cesRCSSearch!Location3))

This works in that it uses the fields to filter the query but when Location1 is empty there are no results as you can see from the code.

View 6 Replies View Related

Queries :: Append Query - INSERT INTO Statement Contain Unknown Field

Sep 19, 2013

I have two tables each with an ID field (autonumber/PK/No Dup etc).

I want to append two fields from one table to the other table. I have set up an Append Query to do this but it won't work - I get the following error - "The INSERT INTO statement contains the following unknown field: 'FiID'...."

View 2 Replies View Related

Queries :: Use Of String Expression As Field Definition And ARGUMENT In IIF Statement

Apr 25, 2014

I am developing a calender to display HOTEL room occupancy (past,present) and combine with future "outlook" dates and 1/0 values from active registrations that go beyond the present date.

I am working with MS ACCESS 2007. My problem is ONE SPECIFIC QUERY AND IIF STATEMENT. I want to concatenate some text (using &) along with numbers converted to text (using the CSTr function). I am using iif function and I want to use the full text string as a variable argument to be executed in the iif function. The result of the &concatenate is a text field like [p1] or [p2] or [p#] with numbers 1-31.

But, I do not want the final result as the argument. I want the query and iif to use the string expression written into the argument as the variable argument that can be calculated based on OTHER numbers that change everyday in the daily run of the calender.

The field in the statement [calc number] is a date conversion factor that changes everyday.

I want the iif statement to execute using the string as a variable argument. I am writing only within the QUERY to define the query object. I am not writing into any SQL module or code. My field definition and iif statement is below (calc number changes everyday)

CalDate18: iif(18 greater date();"[p" & [calc number] & "]";0

I do not have greater-than key on this international keyboard !

When I use this in an update query, I get format conversion error. When I use the same definition in MAKE-TABLE query, it gives the resolved value "[p1]" for the value of [CalDate18] ......... that is not what I want.

I want the string to be taken literally and executed. Seems there may be a special character to precede the argument or WRAP the argument such as done in Excel. Example # "[p" & [calc number] & "]" #

View 7 Replies View Related

Queries :: Remove Grouping On The Field If Do Not Select A Value For It

Sep 4, 2014

I'm trying to allow my users to do some analysis of existing data. they would like to be able to generate a report which will summarize sales orders against the month they were placed. They would also like to summarize this by between 1 and 4 other fields.

I have created a "filter" form to allow them to choose the values for each of the 4 fields and my plan is that they will leave them blank if they do not want to narrow them down. My problem is that I would like to remove the grouping on the field if they do not select a value for it.

Example data:

Field1, Field2, Field3, Field4, Cost, Month, Year
1,2,3,4,£20,4,2014
1,3,4,5,£10,4,2014
1,2,4,5,£5,4,2014

If they select nothing for any of the fields I would just want to see that my total for April 2014 is £35

If they select 1 in Field1 then I want to see one line with a total of £35 (i.e. it ignores the distinction of the other selectable fields)

If they select 1 in Field1 and 2 in Field2 the total would be £25

If they select 2 in Field2 and 4 in Field3 the total would be £5

etc. etc.

I am struggling because I need the distinct records to allow me to group on them when I need to but if I don't need to group on them I need to ignore the grouping.

View 6 Replies View Related

Efficient Way Of Setting Value Of A Textbox To The Result Of A Select Query

Apr 19, 2005

Anyone know an efficient way of setting the value of a textbox to the result of an sql query?

I am using the following, but it seems to be slow when populating a large form:

Make.RowSource = "SELECT BarcodeDATA.Make FROM (Customers RIGHT JOIN CustomerSales ON Customers.CustomerID = CustomerSales.CustomerID) LEFT JOIN BarcodeDATA ON CustomerSales.ItemNum = BarcodeDATA.ItemNum WHERE (((CustomerSales.ItemNum)=[Forms]![FormCheckConsignmentStatus]![ItemNum])); "

Make.Requery

Make.Value = Make.Column(0, 0)


Let me know if there is a better way to do this.

View 1 Replies View Related

Queries :: Omit Records With Blank Field - Criteria With IFF Statement And Checkbox

Apr 18, 2013

I'm having an issue getting my query to omit records with a blank field - in fact, it omits all records.

What I'm trying to do is:

I have a list of customers, with phone and email addresses. I want to filter via query for only customers with their email address's entered.

Here is what I have:

IIf([Forms]![AdvancedReporting]![Check230]=-1,"*",Null)

View 14 Replies View Related

Queries :: Query To Select All Data Regarding A Clicked Field

Mar 1, 2015

I have three tables. TableA contains certain order information, such as the username of the employee, type of order, alias number, etc. TableB contains phone numbers, username of the employee, etc. TableC contains supervisor names and alias numbers.I didn't make these tables but that's what I'm working with. I connected TableA to TableB with the username of the employee, and then TableA to TableC using the alias numbers.

I have a report that summarizes how many orders of each type there are. It shows the supervisor, employee username, alias numbers and then each type of order with the amount of orders of each type under the headers.My boss wants to be able to click on the amount of that type of order and have it show him the details for those orders. This is where my problem is.

I was able to use an Inner Join type of query that allows me to filter the data by order type (however, I have to make a new query for each order type since I'm not too experienced on this). The problem is that I cannot find a way to have a query filter the data by order type AND employee username, so that it only displays the orders taken by a certain employee and it only contains one order type at a time, depending on which order type you clicked.

View 14 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







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