Module/Macro to copy paste from one field in form to another

reswob

New member
Local time
Today, 13:30
Joined
Oct 23, 2008
Messages
1
I'm an Access noob and I've taken over an already created DB. While I'm somewhat familiar with creating macros in Excel, working with VBA in Access seems to be a totally different animal. Here's my question and I apologize if I'm in the wrong category:

Is there a way to create a macro or a module that will copy the text in one field on a form and paste it to another field on the same form?

If so, can I also append text as I paste it?

I need to take the username that's in one field and paste it into a different field and add the text "@domain.com" at the end (effectively creating an email address).


Thanks

Craig
 
Use the command button wizard and create a command button for closing your form.

Then find the code created by the command button wizard and delete this portion:

doCmd.close

now assuming you have two text boxes on your form, one with a person's name which for this example I will call txtName and the other text box contains the last part of the e-mail address which I will call txtEmail

now in the command button function where the code portion doCmd.Close used to be add the following:

'Add a string variable,
Dim strEmailSuffix as string

'set the string variable to the contents of the text box txtEmail
strEmailSuffix = txtEmail

'Now clear the txtEmail text box
txtEmail = ""

'now set the text box txtEmail to the newly formed e-mail address
txtEmail = txtName & strEmailSuffix
 
Macro - SetValue

If you're wanting to do this in a macro you should look at the SetValue action when you create a Macro, this should cover what you're after.

You should also be able to append the domain on the end by concatenating the pasted text and "@domain.com".

There are two Arguments to the SetValue Action:

Item - this will be your field which you want to set the value to, i.e. the field that will have the e-mail address in at the end.

e.g. Forms![Frm_Main]![EmailField]

Expression - This will give the field the value you want, this is where you stipulate the copy field and "@domain.com".

e.g. Forms![Frm_Main]![NameField] & "domain.com"

You can attach this macro to a button or an event on your Form.Hope this helps.

Gareth
 

Users who are viewing this thread

Back
Top Bottom