How to populate a field with another field?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can somebody please show me how to populate the technical name & phone number
fields with the value of Business name & phone number field if the button "
check here if Business name is same as Technical name"?
thank you
 
fifi said:
Can somebody please show me how to populate the technical name & phone number
fields with the value of Business name & phone number field if the button "
check here if Business name is same as Technical name"?
thank you

Add code to your Form's OnCurrent event. You'll need to use the correct
control and field names, but your code should look something like this:

If BizNameSameAsTechName Then
TechName.ControlSource = "BizName"
TechPhone.ControlSource = "BizPhone"
Else
TechName.ControlSource = "TechName"
TechPhone.ControlSource = "TechPhone"
EndIf


An alternate design would be to set the control source for each control to
the appropriate field, and to keep the names the same, use code like this:

If BizNameSameAsTechName Then
TechName = BizName
TechPhone = BizPhone
EndIf

And then, in TechName's AfterUpdate event:

If TechName <> BizName Then BizNameSameAsTechName = False

And a similar line in TechPhone's AfterUpdate.


Or, if you REALLY want to do things the right way, you could set up a whole
new table for Contacts, and a table to map contacts to Businesses, with
fields for BizID, ContactID, Description. Then you could add a "Technical"
Contact to a Business, or a "Sales" Contact, a "Billing" Contact, etc.

Hope this helps!
 
thanks JonOfAllTrades for your response, but the only pb I have is with your
if. Because I want the techname to equal the bizname
techphone num =biz phone num
tech email=biz email
tech faxnum=bizfaxnum
when the " click here if biz contact is same as tech contact" button.
 
fifi said:
thanks JonOfAllTrades for your response, but the only pb I have is with your
if. Because I want the techname to equal the bizname
techphone num =biz phone num
tech email=biz email
tech faxnum=bizfaxnum
when the " click here if biz contact is same as tech contact" button.

Ah! You have a button, not a check box. In that case, you can do this very
simply. In the button's OnClick event, add code like you just posted, only
with the controls' names. If you haven't given your controls specific names,
they will have default names like "Text1," "Command2."
Note that if you have spaces or dashes in a control's name, they are
replaced by underscores for Visual Basic. So if the control that corresponds
to the technical contact phone number is called "Tech Phone" and the biz
phone is called "Biz Phone," your Visual Basic code would look like this:

Tech_Phone = Biz_Phone

And so forth.
 
Oh I am so sorry JonOfAllTrades, but I actually have a check box. I am new
in this, so if you could tell me more explicitely where to go and what to type
Thank you so much for your time
 
fifi said:
Oh I am so sorry JonOfAllTrades, but I actually have a check box. I am new
in this, so if you could tell me more explicitely where to go and what to type
Thank you so much for your time

:) No problem. Going back to my first post, this is what I would recommend:

Open the Form in question
Open the Properties pane, and click the Events tab
Under OnCurrent, select [Event Procedure], this will let you creat Visual
Basic code
Click the ellipses next to OnCurrent to edit the code
Inside Form_Current, add code like this:

If BizNameSameAsTechName Then
TechName = BizName
TechPhone = BizPhone
TechEMail = BizEMail
EndIf

Only, you will need to replace "BizNameSameAsTechName" with the name of your
check box. You can find this under the Other tab for the Properties page for
your control. You will also need to change "TechName," "TechPhone,"
"BizName," etc. to the names of the appropriate controls.
How's that?
 
I don't see oncurrent in the Event tab. I see onclick, afterupdate....
JonOfAllTrades said:
fifi said:
Oh I am so sorry JonOfAllTrades, but I actually have a check box. I am new
in this, so if you could tell me more explicitely where to go and what to type
Thank you so much for your time

:) No problem. Going back to my first post, this is what I would recommend:

Open the Form in question
Open the Properties pane, and click the Events tab
Under OnCurrent, select [Event Procedure], this will let you creat Visual
Basic code
Click the ellipses next to OnCurrent to edit the code
Inside Form_Current, add code like this:

If BizNameSameAsTechName Then
TechName = BizName
TechPhone = BizPhone
TechEMail = BizEMail
EndIf

Only, you will need to replace "BizNameSameAsTechName" with the name of your
check box. You can find this under the Other tab for the Properties page for
your control. You will also need to change "TechName," "TechPhone,"
"BizName," etc. to the names of the appropriate controls.
How's that?
 
fifi said:
I don't see oncurrent in the Event tab. I see onclick, afterupdate....

OnCurrent occurs for the form as a whole, not the individual controls. To
select the form, click on the dark gray background around your form. You may
need to maximize the window.
 
Fifi,

The form's Current evnt is not applicable here, nor is the Click event
of the checkbox.
The applicable event is the After Update event property of the Checkbox.
Like this...

If Me.NameOfYourCheckbox Then
Me.techname = Me.bizname
Me.techphone_num = Me.biz_phone_num
Me.tech_email = Me.biz_email
Me.tech_faxnum = Me.bizfaxnum
Else
Me.techname = Null
Me.techphone_num = Null
Me.tech_email = Null
Me.tech_faxnum = Null
End If
 
Steve Schapel said:
Fifi,

The form's Current evnt is not applicable here, nor is the Click event
of the checkbox.
The applicable event is the After Update event property of the Checkbox.
Like this...

If Me.NameOfYourCheckbox Then
Me.techname = Me.bizname
Me.techphone_num = Me.biz_phone_num
Me.tech_email = Me.biz_email
Me.tech_faxnum = Me.bizfaxnum
Else
Me.techname = Null
Me.techphone_num = Null
Me.tech_email = Null
Me.tech_faxnum = Null
End If

Almost. The various Tech fields still have values, and we need to be able
to get to them when the check box is clear. Setting them to null will erase
them, assuming the control source remains unchanged.
But yes, the AfterUpdate event would work quite well. Fifi, you can use Mr
Schapel's code, but do please skip the Else clause, meaning everything from
Else (inclusive) to End If (exclusive).
All those "Me"s are not necessary, and IMHO can be confusing for newbies.
Is there a performance improvement?
 
I have just one more question: how do I make the button have a dot only when
it's clicked. The reason, I am asking this is that sometimes, when I open
the form, the dot is already, making have to click the button twice, before
the business values get copied to the tech values
 
Back
Top