UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
2 Pages V  1 2 >  (Go to first unread post)
   Reply to this topicStart new topic
> Checkbox To Copy Field To Another Field, Access 2010    
 
   
wjm821
post Jul 21 2019, 08:00 AM
Post#1



Posts: 48
Joined: 18-April 18



Creating a sales receipt or invoice. tblCustomer has fields HomeAddress, ShipAddress and Checkbox. On the Form I have home address and shipping address with the checkbox, click on checkbox to copy HomeAddress to ShipAddress if it's the same address.

Doing searches everywhere I've found a code, but it doesn't work

Private Sub CopyAddress_AfterUpdate()
If CopyAddress = True Then
Me![ShipAddress] = Me![HomeAddress]
End Sub

also tried
Private Sub CopyAddress_AfterUpdate()
If CopyAddress = True Then
Me.ShipAddress = Me.HomeAddress
End Sub

What am I missing? Something in the ShipAddress field? Setting on the Form?

Thank you for your help
Go to the top of the page
 
theDBguy
post Jul 21 2019, 08:24 AM
Post#2


Access Wiki and Forums Moderator
Posts: 76,028
Joined: 19-June 07
From: SunnySandyEggo


Hi. When you say it doesn’t work, what do you mean? Were you getting an error? If so, what was the error message?

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
RJD
post Jul 21 2019, 08:25 AM
Post#3


UtterAccess VIP
Posts: 9,917
Joined: 25-October 10
From: Gulf South USA


Hi: Looks like you are missing the "End If" ... so you could write the code like this ...

Private Sub CopyAddress_AfterUpdate()
If CopyAddress = True Then
Me![ShipAddress] = Me![HomeAddress]
End If
End Sub

Or ...

Private Sub CopyAddress_AfterUpdate()
If Me!CopyAddress = True Then Me![ShipAddress] = Me![HomeAddress]
End Sub

Or even just ...

Private Sub CopyAddress_AfterUpdate()
If Me!CopyAddress Then Me![ShipAddress] = Me![HomeAddress]
End Sub

(Note I added the Me!, although it will work without it.)

But also, I assume you have a yes/no table field named CopyAddress (not Checkbox, as in your post first line). Is that correct? If you simply want to copy the address, a command button should do just as well, unless you always want to indicate that attribute in your record.

And what I usually do is not have an indicator, but use code when printing the Invoice/Receipt to check for a null ShipAddress and if so, use the HomeAddress.

HTH
Joe

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
wjm821
post Jul 21 2019, 08:54 AM
Post#4



Posts: 48
Joined: 18-April 18



Yes in my tblCust I have yes/no field

I tried all 3 suggestions and nothing works.

Fields on form/table are HomeAddress, ShipAddress and yes/no, no unbound text boxes. Looked at the spelling, all is correct.


what would vba code for a command button to copy the field
This post has been edited by wjm821: Jul 21 2019, 08:55 AM
Go to the top of the page
 
Jeff B.
post Jul 21 2019, 08:57 AM
Post#5


UtterAccess VIP
Posts: 10,268
Joined: 30-April 10
From: Pacific NorthWet


Do you have "Option Explicit" set? Have you inserted a breakpoint and traced the flow? (… and, as already asked, are you getting an error message? When you say "doesn't work", we have to guess what that means)

--------------------
Regards

Jeff Boyce
Microsoft Access MVP (2002-2015)

Mention of hardware or software is, in no way, an endorsement thereof. The FTC of the USA made this disclaimer necessary/possible.
Go to the top of the page
 
RJD
post Jul 21 2019, 08:58 AM
Post#6


UtterAccess VIP
Posts: 9,917
Joined: 25-October 10
From: Gulf South USA


Hi: Well, obviously something is going on that we cannot see. I tested my suggestions and all work. Take a look at the attachment.

If you are still having this issue, please post a db with the table and form, with some example records in the table. Then we can see what is really going on.

HTH
Joe
Attached File(s)
Attached File  FormAction.zip ( 23.03K )Number of downloads: 1
 

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
wjm821
post Jul 21 2019, 09:01 AM
Post#7



Posts: 48
Joined: 18-April 18



no error messages, just looking at the table after update then saving record. Will say when box is checked the ShipAddress is still
Go to the top of the page
 
RJD
post Jul 21 2019, 09:05 AM
Post#8


UtterAccess VIP
Posts: 9,917
Joined: 25-October 10
From: Gulf South USA


If using a command button, the code is ...

Me!ShipAddress = Me!HomeAddress

But take a look at the revised demo attached and see how it differs from what you are doing. And again, if still an issue, please post a db for us to look at. Probably something very simple.

HTH
Joe
Attached File(s)
Attached File  FormAction_Rev1.zip ( 23.67K )Number of downloads: 3
 

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
wjm821
post Jul 21 2019, 09:06 AM
Post#9



Posts: 48
Joined: 18-April 18



Sending my database. The file you sent doesn't work for me so I'm guessing it's in the option setting for the database itself
Go to the top of the page
 
RJD
post Jul 21 2019, 09:08 AM
Post#10


UtterAccess VIP
Posts: 9,917
Joined: 25-October 10
From: Gulf South USA


Hmmm ... The files I sent work without a problem here. And I do not see your posted file. Did you zip it first?

What do you mean by "The file you sent doesn't work for me"?

HTH
Joe

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
wjm821
post Jul 21 2019, 09:09 AM
Post#11



Posts: 48
Joined: 18-April 18



The database has a lot more address fields, just trying to get homeaddress and shipaddress working, then I'll just add the rest in
Go to the top of the page
 
RJD
post Jul 21 2019, 09:12 AM
Post#12


UtterAccess VIP
Posts: 9,917
Joined: 25-October 10
From: Gulf South USA


QUOTE
The database has a lot more address fields, just trying to get homeaddress and shipaddress working, then I'll just add the rest in

Understand. But if we don't have a good description of what you are doing, or have the db in-hand, it will be very difficult to help.

HTH
Joe

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
wjm821
post Jul 21 2019, 09:13 AM
Post#13



Posts: 48
Joined: 18-April 18



resending as zip file.

Neither file you sent updates to the shipaddress field
Attached File(s)
Attached File  Test2.zip ( 513.38K )Number of downloads: 1
 
Go to the top of the page
 
RJD
post Jul 21 2019, 09:38 AM
Post#14


UtterAccess VIP
Posts: 9,917
Joined: 25-October 10
From: Gulf South USA


QUOTE
Neither file you sent updates to the shipaddress field

I assume you mean in my demo, not in your db. It works without any problems here, also in A2010. Have you checked your references?

I also looked at your posted db. I used frmInvoice, and added a command button to copy the city control contents (Text283) to the ship city (SCity) (after adding a city in the underlying record for customer 1), then save using the Dirty approach. It works without a problem.

Please test what I have done and see if this works for you.

HTH
Joe
Attached File(s)
Attached File  UA_wjm821_20190721_Rev1.zip ( 511.75K )Number of downloads: 3
 

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
wjm821
post Jul 21 2019, 09:41 AM
Post#15



Posts: 48
Joined: 18-April 18



I'm sorry I sent the wrong db, this is the correct one
Attached File(s)
Attached File  PB1.zip ( 728.11K )Number of downloads: 4
 
Go to the top of the page
 
wjm821
post Jul 21 2019, 09:42 AM
Post#16



Posts: 48
Joined: 18-April 18



yes your demo, so it has to be a setting somewhere that is a default in my a2010
Go to the top of the page
 
RJD
post Jul 21 2019, 09:50 AM
Post#17


UtterAccess VIP
Posts: 9,917
Joined: 25-October 10
From: Gulf South USA


Hi: I tested your last db, and clicking the "Copy Address" checkbox copies the address without a problem. I added a record save so that the results would appear immediately in the table. Again, no problem.

So, I am at a loss why this is not working for you there, and not giving you any indications.

Perhaps someone else can think of a reason this is happening, because I am currently fresh out of ideas. I will put out a call and see if someone else has ideas.

HTH
Joe

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
wjm821
post Jul 21 2019, 09:55 AM
Post#18



Posts: 48
Joined: 18-April 18



All the ways you said to try was what I found through Google, except 1. Something is wrong somewhere I looked in File/Options/General and Current DB

Thank you for your time, batting my head on this for 2 days
Go to the top of the page
 
RJD
post Jul 21 2019, 10:02 AM
Post#19


UtterAccess VIP
Posts: 9,917
Joined: 25-October 10
From: Gulf South USA


Yes, sounds like you have a problem locally, probably with your setup, since it all works fine here. (By the way, did you check your references?)

I put out a call to the VIPs to see if we can get more eyes/brains on this for you. Let's see what turns up. Lots of experience/expertise here, so maybe a solution will emerge.

Good luck. I'll look back at this from time to time to see if any suggestions come forth and anything gets resolved.

Regards,
Joe

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
wjm821
post Jul 21 2019, 10:12 AM
Post#20



Posts: 48
Joined: 18-April 18



attached is the references
Attached File(s)
Attached File  references.gif ( 5.71K )Number of downloads: 0
 
Go to the top of the page
 
2 Pages V  1 2 >


Custom Search


RSSSearch   Top   Lo-Fi    19th August 2019 - 10:59 PM