Duplicate data from field into another field in same form?

A

Andi

Can I duplicate data from one field on a form into another field in the same
form?

For example:
On our exhibitor entry form, the Program Contact info (fields for name,
address, phone, fax, email) is entered first. Mail Contact info is often the
same, but not always.

Is it possible to autopopulate the Mail Contact with the data from the
Program Contact, but allow me to enter new data if necessary?

If so, can you tell me exactly how?

Thanks!
 
J

John W. Vinson

Can I duplicate data from one field on a form into another field in the same
form?

For example:
On our exhibitor entry form, the Program Contact info (fields for name,
address, phone, fax, email) is entered first. Mail Contact info is often the
same, but not always.

Is it possible to autopopulate the Mail Contact with the data from the
Program Contact, but allow me to enter new data if necessary?

Sure. You'll need just a little bit of VBA code.

Assuming there are textboxes named MailAddress, MailPhone, MailFax, MailEmail
and ProgramAddress, ProgramPhone, ProgramFax, ProgramEmail you can put code in
the AfterUpdate event of each Program textbox such as:

Private Sub ProgramAddress_AfterUpdate()
If IsNull(Me!MailAddress) Then
Me!MailAddress = Me!ProgramAddress
End If
End Sub

This checks to see if the mail address control is empty (wouldn't want to
stomp on data that was there!) and if so copies the value.

A couple of suggestions: Don't use Name as the Name of a field or a control;
it's a reserved word and can cause problems. People's names should generally
be stored in (at least) two fields - LastName, FirstName; it's easy to
concatenate them for display and easier to search and sort. Address should
probably also be split up - Address (or even AddressNo and Street), City,
State, Postcode. You may also want to consider a separate Phones table - lots
of folks have several phones these days, and it can be treated as a one to
many (with a PhoneType field for Work, Home, Cell, Fax, ...).


John W. Vinson [MVP]
 
A

Andi

John:

Thanks very much for your response -- sorry about the delay in getting back
to you.

I tried the code you suggested, but I must be entering it incorrectly. When
I get to...
If IsNull(
....that line turns red and displays IsNull(Expression) As Boolean

The first time I completed the code, the program data displayed in the mail
field. However, when I entered new data in the mail field, it also changed
the program data.

Any thoughts?
 
J

John W. Vinson

Thanks very much for your response -- sorry about the delay in getting back
to you.

I tried the code you suggested, but I must be entering it incorrectly. When
I get to...
If IsNull(
...that line turns red and displays IsNull(Expression) As Boolean

The first time I completed the code, the program data displayed in the mail
field. However, when I entered new data in the mail field, it also changed
the program data.

Please post your actual code, and the actual names of the controls involved.

John W. Vinson [MVP]
 
A

Andi

John:

Thanks again for your help.

The current code for both fields is the same until near the end of the code.
I have put a dotted line where it changes.

What I would like to do is have the PRG CONTACT info autopopulate the MAIL
CONTACT field, but then allow me to change the info in MAIL CONTACT if
necessary (without affecting the PRG CONTACT info).



Option Compare Database

Private Sub Find_Click()
On Error GoTo Err_Find_Click


Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_Find_Click:
Exit Sub

Err_Find_Click:
MsgBox Err.Description
Resume Exit_Find_Click

End Sub
Private Sub Add_New_Click()
On Error GoTo Err_Add_New_Click


DoCmd.GoToRecord , , acNewRec

Exit_Add_New_Click:
Exit Sub

Err_Add_New_Click:
MsgBox Err.Description
Resume Exit_Add_New_Click

End Sub
Private Sub Find_Acronym_Click()
On Error GoTo Err_Find_Acronym_Click


Screen.PreviousControl.SetFocus
DoCmd.FindNext

Exit_Find_Acronym_Click:
Exit Sub

Err_Find_Acronym_Click:
MsgBox Err.Description
Resume Exit_Find_Acronym_Click

End Sub
Private Sub Acronm_Click()
On Error GoTo Err_Acronm_Click


Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_Acronm_Click:
Exit Sub

Err_Acronm_Click:
MsgBox Err.Description
Resume Exit_Acronm_Click

End Sub
Private Sub Command276_Click()
On Error GoTo Err_Command276_Click


Screen.PreviousControl.SetFocus
DoCmd.FindNext

Exit_Command276_Click:
Exit Sub

Err_Command276_Click:
MsgBox Err.Description
Resume Exit_Command276_Click

End Sub

Private Sub PRG_CONTACT_BeforeUpdate(CANCEL As Integer)

End Sub
---------------------------------------------------------------

Private Sub MAIL_CONTACT_BeforeUpdate(CANCEL As Integer)

End Sub

Private Sub PRG_CONTACT_BeforeUpdate(CANCEL As Integer)

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top