Copy field on checkbox

JoeyJoystick

Registered User.
Local time
Today, 09:10
Joined
Jul 23, 2015
Messages
15
Hi All,

I have a checkbox in a form. The purpose of this field is to indicate if the billing address is the same as the shipping address.

The forms purpose is to enter new accounts. The first tab has all general info including shipping address. The second tab includes, among other things, the billing address. I have made a checkbox here which indicates that the billing and shipping address are the same. It would be nice that when this is selected that it automatically copies the value previously entered into the corresponding field of the billing address.

I have the following code for this.

Private Sub chkShippingIsBilling_AfterUpdate()
If Me.chkShippingIsBilling.Value = True Then
fldBillingAddress_StreetLine01 = fldShippingAddress_StreetLine01

End If


End Sub

And, it obviously doesn't work and I have no idea why.

Can somebody please help me or guide me in the right direction?


Thanks you very much,


Joost (Joey)
 
there are 2 tabs meaning 2 subforms.
forms!Mainform!subformName.form!fldBillingAddress_StreetLine01 = fldShippingAddress_StreetLine01
 
Hi arnelgp,

Thank you very much for the idea. However, whatever I tried, I could not get it to work using your syntax. Did some googling on this again and many other but similar syntaxes did not work for me either. Not sure what I am doing wrong. However, when I entered the 'Me.' syntax I got an option to select some values and I ended up with the following code and it worked after some trial and error. Added an ElseIf to clear the fields.

Private Sub chkShippingIsBilling_AfterUpdate()
If Me.chkShippingIsBilling.Value = True Then
Me.txtBillingAddress_StreetLine01.Value = Me.txtShippingAddress_StreetLine01.Value
Me.txtBillingAddress_StreetLine02.Value = Me.txtShippingAddress_StreetLine02.Value
Me.txtBillingAddress_StreetLine03.Value = Me.txtShippingAddress_StreetLine03.Value
Me.txtBillingAddress_City.Value = Me.txtShippingAddress_City.Value
Me.txtBillingAddress_PostalCode.Value = Me.txtShippingAddress_PostalCode.Value
Me.cmbBillingAddress_Province.Value = Me.cmbShippingAddress_Province.Value
Me.cmbBillingAddress_Country.Value = Me.cmbShippingAddress_Country.Value
Else
If Me.chkShippingIsBilling.Value = False Then
Me.txtBillingAddress_StreetLine01.Value = ""
Me.txtBillingAddress_StreetLine02.Value = ""
Me.txtBillingAddress_StreetLine03.Value = ""
Me.txtBillingAddress_City.Value = ""
Me.txtBillingAddress_PostalCode.Value = ""
Me.cmbBillingAddress_Province.Value = ""
Me.cmbBillingAddress_Country.Value = ""
End If
End If

End Sub
So the only question that remains is why your syntax does not work. I saw several articles saying that it is not wise to use the 'Me.' syntax. So I am a little concerned about the impact of my approach.

Anyway, you still guided me in the right direction, so thanks a lot for your help!
 
Hi JHB, I have been looking for over an hour now and can not find it again. When I wanted to go through yesterdays history I came to realization that my history is only turned on for the present day. Not my computer...

If I run into it again I will send it to you at a later stage. From what I remember though it was a mentioning of later versions of Access (2010 & 2013) where the use of this in some instance may cause database corruption.

Anyway, you say very confidently that this is the correct way of doing it and it works so I am a happy bunny.

Best Regards
 
... From what I remember though it was a mentioning of later versions of Access (2010 & 2013) where the use of this in some instance may cause database corruption.
I run MS-Access 2010 now and have used MS-Access since version 95, never had any corruption cause by using Me.!
 

Users who are viewing this thread

Back
Top Bottom