Concatenate Text To Populate 'Customer ID' Box

Pacman52

Active Member
Joined
Jan 29, 2009
Messages
416
Office Version
  1. 365
Platform
  1. Windows
Hi all, I'm trying to work out how concatenate some text and a date together in VBA on a Userform and dispite many google searches just can't seem to work out how to do this in code if indeed it is actually possible?

So the issue:
On my Userform ("Events") I have 3 text boxes : (1) txtEventName. (2) txtsDate (formatted as a date), (3) txtEventCode

What I'm trying to accomplish is once data has been entered in txtEventName and txtsDate then the txtEventCode box is automatically populated to create an Event Code by joining the data together with a seperator "-"

For example if I enter "Summer Fair" in txtEventName and 23/12/2023 in txtsDate then I would like txtEventCode to automatically be populated with "Summer Fair - 23/12/2023"

The event code will eventually be used so it can be searched upon in case any changes to the data for that event need to be changed. I've done this using a formula in the worksheet but just can't work out how to do this in VBA on the userform.

Thanks in advance for any advice or solutions offered.

Paul
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi Kerryx thanks so much for the reply, but as mentioned in my original question I already know how to do this in a formula.

What I am trying to work out is how to do the same thing in VBA code so that when a user completes the Userform the event code text box is automatically filled with the combined text value so that once the user clicks the form 'Save' button then all the values in the form go over to the spreadsheet.

Paul
 
Upvote 0
Your date should already be a string and correctly formatted so it is a simply a matter of concatenating as you would in Excel ie:
VBA Code:
    txtEventCode.Value = txtEventName.Value & " - " & txtsDate.Value
 
Upvote 0
Your date should already be a string and correctly formatted so it is a simply a matter of concatenating as you would in Excel ie:
VBA Code:
    txtEventCode.Value = txtEventName.Value & " - " & txtsDate.Value

Thanks so much Alex - that works perfectly,
as a follow up question, is there a way to only use the first 6 characters of the EventName as an example
The event is "Summer Fair" and the date is 23/12/2023 so the event code would end up being 'Summer - 23/12/2303' ?
 
Upvote 0
Sure,
VBA Code:
txtEventCode.Value = Trim(Left(txtEventName.Value, 6)) & " - " & txtsDate.Value
 
Upvote 0
Solution
Hi Kerryx thanks so much for the reply, but as mentioned in my original question I already know how to do this in a formula.

What I am trying to work out is how to do the same thing in VBA code so that when a user completes the Userform the event code text box is automatically filled with the combined text value so that once the user clicks the form 'Save' button then all the values in the form go over to the spreadsheet.

Paul
no problem just misread the question, late night 😃
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top