Mailing Address (1 Viewer)

pcastner1

Registered User.
Local time
Today, 04:51
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
 

essaytee

Need a good one-liner.
Local time
Today, 21:51
Joined
Oct 20, 2008
Messages
512
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.
 

essaytee

Need a good one-liner.
Local time
Today, 21:51
Joined
Oct 20, 2008
Messages
512
To follow-up, I prefer the Me dot notation, as intellisense kicks in and makes life a little easier.

Me!TextControl

as

Me.TextControl
 

pcastner1

Registered User.
Local time
Today, 04:51
Joined
Dec 29, 2018
Messages
19
Wow! now that I look at it what a bonehead mistake. Thanks for the help.
 

pcastner1

Registered User.
Local time
Today, 04:51
Joined
Dec 29, 2018
Messages
19
I made the changes and when I check the box nothing happens
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:51
Joined
Sep 21, 2011
Messages
14,238
Walk through the code line by line
 

pcastner1

Registered User.
Local time
Today, 04:51
Joined
Dec 29, 2018
Messages
19
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
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:51
Joined
Sep 21, 2011
Messages
14,238
Look at your code?
You set one thing if true and set another if false?
 

pcastner1

Registered User.
Local time
Today, 04:51
Joined
Dec 29, 2018
Messages
19
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
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:51
Joined
Sep 21, 2011
Messages
14,238
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
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:51
Joined
Sep 21, 2011
Messages
14,238
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.?
 

MrHans

Registered User
Local time
Today, 13:51
Joined
Jul 27, 2015
Messages
147
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
 

Micron

AWF VIP
Local time
Today, 07:51
Joined
Oct 20, 2018
Messages
3,478
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

Top Bottom