Mailing Address

pcastner1

Registered User.
Local time
Today, 11:52
Joined
Dec 29, 2018
Messages
19
I have an issue with a code I'm using. I have a code that when I enter the address info, if the mailing address is the same you would use the checkbox to fill out the mailing address.

I'm using the code below.

Private Sub ChkMailingAddressSame_AfterUpdate()
If ChkMailingAddressSame = True Then
Me!Address = Me!MailingAddress
Me!Apt_Lot = Me!MApt_lot
Me!City = Me!MCity
Me!State = Me!MState
Me!Zip = Me!MZip
Else
Me!Address = ""
Me!Apt_Lot = ""
Me!City = ""
Me!State = ""
Me!Zip = ""
End If
End Sub
 
It appears you are assigning the mailing address to the normal address, when in fact you should be assigning the normal address to the mailing address.

Change
Code:
Me!City = Me!MCity
to
Code:
Me!MCity = Me!City
do this for the rest.

Reverse it also for the false part of the condition.
 
To follow-up, I prefer the Me dot notation, as intellisense kicks in and makes life a little easier.

Me!TextControl

as

Me.TextControl
 
Wow! now that I look at it what a bonehead mistake. Thanks for the help.
 
I made the changes and when I check the box nothing happens
 
Walk through the code line by line
 
Walked through it but doesn't work.
Here is the code:

Private Sub ChkMailingAddressSame_AfterUpdate()
If ChkMailingAddressSame = False Then
Me.MailingAddress = Me.Address
Me.MApt_lot = Me.Apt_Lot
Me.MCity = Me.City
Me.MState = Me.State
Me.MZip = Me.Zip
Else
Me.Address = ""
Me.Apt_Lot = ""
Me.City = ""
Me.State = ""
Me.Zip = ""
End If
End Sub
 
Look at your code?
You set one thing if true and set another if false?
 
Ok changed checkbox to true but no luck.

Private Sub ChkMailingAddressSame_AfterUpdate()
If ChkMailingAddressSame = True Then
Me.MailingAddress = Me.Address
Me.MApt_lot = Me.Apt_Lot
Me.MCity = Me.City
Me.MState = Me.State
Me.MZip = Me.Zip
Else
Me.Address = ""
Me.Apt_Lot = ""
Me.City = ""
Me.State = ""
Me.Zip = ""
End If
End Sub
 
No:banghead:

What I was saying was that if the checkbox logic is true (not True itself) then you set Me.M* otherwise you set Me.* the controls are completely different.

I would have expected to set them for one part of the logic, and clear them for the other.?

Ok changed checkbox to true but no luck.

Private Sub ChkMailingAddressSame_AfterUpdate()
If ChkMailingAddressSame = True Then
Me.MailingAddress = Me.Address
Me.MApt_lot = Me.Apt_Lot
Me.MCity = Me.City
Me.MState = Me.State
Me.MZip = Me.Zip
Else
Me.Address = ""
Me.Apt_Lot = ""
Me.City = ""
Me.State = ""
Me.Zip = ""
End If
End Sub
 
Sorry I'm not understanding.

I don't know how to say it any other way.

Normally code would be along the lines of
Code:
If logic is true
    Me.Control = Me.Control1
else
    Me.Control = ""
EndIf

You on the other hand have code along the lines of
Code:
If logic is true
    Me.Control = Me.Control1
else
    Me.SomeOtherControl = ""
EndIf

When essaytee pointed out your error, you only changed one half of the logic, by the looks of it.?
 
Like this:

Code:
Ok changed checkbox to true but no luck.

Private Sub ChkMailingAddressSame_AfterUpdate()

If ChkMailingAddressSame = True Then

Me.MailingAddress = Me.Address

Me.MApt_lot = Me.Apt_Lot

Me.MCity = Me.City

Me.MState = Me.State

Me.MZip = Me.Zip

Else

Me.MailingAddress = ""

Me.MApt_lot = ""

Me.MCity = ""

Me.MState = ""

Me.MZip = ""

End If

End Sub
 
I prefer the Me dot notation, as intellisense kicks in and makes life a little easier.
Me too, but that's not the primary reason for me.
! provides late bound access to the default member of what proceeds it by passing what follows it as the argument.

If the correct reference is .txtText1 and you write Me!Test1, it won't be caught until run time and only if code executes the line. That could be right away or any time in the future. It won't be caught on compile either. Of course, there are cases where ! is required, such as on a recordset update.
 

Users who are viewing this thread

Back
Top Bottom