Concatenate two columns in an Access table - ms-access

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.

Related

How to roll up a column with a query

i have an acess "query" that consist of Drawing-title and Multiple data per ID. And i would like to roll up this data into separate columns. Thanks in advance.
My query looks like this
And would like to change to this
A CROSSTAB requires 3 fields. You need to calculate a third field as a sequence number for each group that will become RowHeader. This will require a unique identifier field in table - autonumber should serve.
TRANSFORM First(Data) AS FirstData
SELECT DWG
FROM tableORquery
GROUP BY DWG
PIVOT DCount("*","tableORquery","DWG='" & [DWG] & "' And ID<" & [ID])+1;

How to concatenate three fields in table into one table?

I would like to concatenate three fields in my MS Access table into one field by using VBA. How can I do this?
I have tried using query to concatenate it and it works, but I would like it to be concatenated and saved in my table instead.
My 3 fields I want to concatenate into 1 field are: CompanyCode,YearCode and PO number.
Currently my table look like this:
Company code YearCode PONumber
ABC 17/ 200
What I want:
PONumber
ABC17/200
Use a query:
Select *, [Company Code] & [YearCode] & [PONumber] As FullNumber
From YourTable
If you insist on having a calculated field in the table itself, use this expression when you - in design view - add the calculated field:
[Company Code] & [YearCode] & [PONumber]
As mentioned #Andre, highly not recommended to use calculated fields in Access tables at all, this feature is quite buggy. But in some cases it's reasonable to store combined code in separate regular field for performance improvement, despite this denormalizes the database structure. You can store combined code in form's BeforeUpdate event:
Me!PONumberFull = Me![Company code] & Me!YearCode & Me!PONumber
Also I'd recommend to do not store "/" in YearCode, just number. In this case the code will be
Me!PONumberFull = Me![Company code] & Me!YearCode & "/" & Me!PONumber

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.

Access, lookup for data in another table if matches

I have a Union query with invoice data like invoice number, supplier and so on. This query is created for the purpose of providing credit note information.
My problem arise when I would like to provide exchange rate for invoices in different currencies. If there is for example RON currency, I need to check currency and date of invoice and then provide value from another table.
I stored currencies and their values in another database. I wanted to use Dlookup function but it works only current database. Not sure what can I do. Is VBA needed here or it can be avoided?
Edit:
Having problem with syntax:
Query:
SELECT [Faktury].InvoiceNumber, [Faktury].InvoiceDate, [Faktury].InvoiceCountry, [Faktury].Currency, DLookUp("Value","Tabela1","Currency1 =" & [Currency]) AS Wyr1
FROM [Faktury];
Dlookup syntax:
DLookUp("Value";"Tabela1";"Currency1 =" & [Currency])
Query has column with Currency used in invoice and Tabela1 has Currency1 and Value. I get error or no value is shown...
To access a a table in another database you can create a link to it:
Go to External Data > Access (although you could use any other type of data source) > choose the database file, and select Link to the data source by creating a linked table.
Then click Ok and select the table(s) you want to link (i.e. use in your database). Now you can use the table (Currency in my example) in your queries or in VBA like a normal table. For example with DLookup in VBA:
MsgBox DLookup("EuroValue", "Currency", "ID='" & InputBox("Currency?") & "'")
or in a (SQL) query:
SELECT EuroValue FROM [Currency] WHERE ID='USD';
or
SELECT DLookUp("EuroValue","Currency","ID='USD'");