Reusing Parameters Passed to Query to Generate Form - ms-access

I have a form in MS Access that uses a query to generate a form. The query looks something like this:
SELECT *
FROM PEOPLE
WHERE LAST_NAME LIKE [Enter Last Name] & "%";
This of course creates a pop-up to enter the last name to search. I want to do an action on the parameter [Enter Last Name], but I cannot figure out how to access this parameter. In a report I just set the value of a textbox to =[Enter Last Name]. Can anyone help me figure this out?

One thing you could do would be to add the parameter as an output column, e.g.
PARAMETERS [Enter Last Name] Text ( 255 );
SELECT People.*, [Enter Last Name] AS theParameter
FROM People
WHERE (((People.LastName) Like [Enter Last Name] & "*"));
Then you could refer to the [theParameter] column in the result set.

Related

Parameter in the Like clause of the criteria in MS Access

I am looking to create a query in MS Access that searches by a name provided by the user. However, I would like to let the user enter only the beginning of the name. So, I would imagine a search criteria like this:
Like "[Enter name: ]*"
How do I achieve this effect?
You put parameter into quotes - so it become just part of string.
Like [Enter name: ] & "*"

DSUM Existing Field in Access Query

I am trying to reference a field in my query in a DSUM Expression in the same query but I can't get it to work. Could you please help?
I want my 'Total $ Accrual' column in the below query to sum the 'Amount $' amounts in the 'Accruals Raw Data' table for each Accrual ID from the 'Accruals Master Data' table (as they are displayed in the query when the query runs).
When I run it the query opens an input box window instead.
I originally tried using the below formula but it says the field may refer to the 'Accrual ID' in more than 1 table, therefore I have tried to reference the field within the query using the screenshot instead.
Total $ Accrual: DSum("[Amount $]","Accruals Raw Data","[Accrual ID]='" & [Accrual ID] & "'")
Many Thanks
Try this:
Total $ Accrual: DSum("[Amount $]","[Accruals Raw Data]","[Accrual ID]='" & [Accruals Master Data].[Accrual ID] & "'")
You have 2 tables in query with the same column name [Accrual ID], so Access asked to clarify which table you are referencing to.

Concatenate name fields in an Access query using IIF() without printing spaces?

First of all, I am a newbie. Please keep that in mind...
That said, I have used a simple formula to concatenate name fields in a student database in Access using a query (I am using Access 2013 but must maintain compatibility with Access 2010). It reads as such:
Student Name: IIf(IsNull([Preferred First Name]),[First Name],[Preferred First Name]) & " " & [Last Name]
Which shows the student's preferred first name and last name, or first name and last name. If it turns out first (preferred or given) is null and/or last is null, obviously it prints null where appropriate.
Example of formula output using fictional names
Well, that is where the issue comes in. As you can see in the example, one student only has first name Christine, which prints as "Christine ". Another only has last name Alexander, which prints as " Alexander". It is printing the space no matter what.
Now I now it is possible using Iif to get around this -- it's used in a sample database like so:
Student Name: IIf(IsNull([Last Name]),IIf(IsNull([First Name]),[First Name]),IIf(IsNull([First Name]),[Last Name],[First Name] & " " & [Last Name]))
I want to incorporate the "Preferred First Name" field into that formula, but I just can't wrap my head around it. It seems to work backwards from how I would say this in natural speech, and it seems to be missing values. In plain English I envision it like this:
If [Last Name] is null, print only [Preferred First Name], unless that is null, in which case print only [First Name], unless that is also null, in which case print null.
Otherwise if [Last Name] has a value, print [Preferred First Name] & " " & [Last Name], unless [Preferred First Name] is null, in which case print [First Name] & " " & [Last Name], unless [First Name] is also null, in which case just print [Last Name].
(To clarify, there are sometimes cases where we are unable to get a student's full name, so I can't simply make all fields required, which is why I want to make sure it prints correctly regardless of what data is available.)
I apologize if this is too simple a question for this site, but it seemed like the best place to ask. Thank you for any help.
You want to use the Trim function. So, your string would look like:
Student Name: Trim(IIf(IsNull([Preferred First Name]),Trim([First Name]),
Trim([Preferred First Name])) & " " & Trim([Last Name]))
Trim each individual field (just in case the data got entered with an extra space or 2, which happens occasionally), and then trim the entire resultant string to get rid of any spaces as well.

Concatenate two columns in an Access table

very simple one. I have got two fields in a table called [First Name] and [Last Name]. I would like to add a new column that is just a combination of [First Name] and [Last Name] - is there a way to do this in Access? I know this can be done in Excel using the Concatenate function.
I would like to do this in the existing table and not in a new query.
Thanks!
As #paxty says, do not do this. You have a simple answer in Access that is not available in Excel, and that is a query. You can base any output that requires that the two names be concatenated on a query.
SELECT FirstName & " " & LastName FROM MyTable
In Access 2010 you can create a "calculated field" for your table; Access applies a formula to create the content of the field. You can enter a formula such as:
FirstName & " " & LastName
You could even do fancier things like have an initial then the last name, if there is a last name, or else show the complete first name, using the Access IIf() and Len() functions.
IIf (Len(LastName) > 0, Left(FirstName, 1) & ". " & LastName, FirstName)
By using a calculated field to join the two names directly in the table... It creates issues down the road. I have two fields First & last name I used a calculated field in the table to join the two together. When you try do a report with those calculated names, it will show only the employee number, not the names. Now I am trying to correct my mistake without having to rebuild the multiple tables I have used this field as a look up in.

MS Access: Using parameters with hyphens in a parameter query

I have serial numbers in the form X-xxxx, where X is an alpha char and x is numeric, I can't seem to get the parameter passed in correctly.
One thing I've tried, which actually works properly in a different database of similar info, is:
Like [Enter Serial Number:] & "-*" Or [Enter Serial Number:]
Any suggestion would be greatly appreciated
It appears to me you want to allow the users to search 2 ways:
enter the full serial number
enter only one character (and return all serial numbers which start with that character)
If that's what you're after, try a query like this:
PARAMETERS [Enter Serial Number:] Text ( 6 );
SELECT p.*
FROM tblPingPong AS p
WHERE
(((p.serial_num)=[Enter Serial Number:]))
OR (((p.serial_num) Like [Enter Serial Number:] & "-*"));
If you are asking the user for the numeric portion:
Like "*-" & [Enter Serial Number:]
However, this will be slow unless your table is quite small. You might like to consider getting the input for the query from a form.