?
Solved

MSACCESS VBA to copy Billing Address to Shipping Address - Bug

Posted on 2010-09-23
7
Medium Priority
?
785 Views
Last Modified: 2012-05-10
I have some code that copies one address (Incident address) to another address field (Home address) at the push of a button in an Access 2007 form.  There is another button that copies the Home address to the Mailing address.

There are 2 buttons, then: btnCopyIncAdd, and btnCopyHomAdd.  Pressing a button should prompt "Are you sure?" with a yes or no.  If the user presses yes, the address is copied.

There are 2 problems:

Pressing btnCopyIncAdd causes Access to seemingly stop responding.  If I wait for about 10 seconds, then maximize a window (Chrome, Outlook, it doesn't really matter) on top of Access, then move that window away, the "Are you sure?" box shows up.  I can press yes, and it seems to work.

Pressing btnCopyHomAdd does the same thing, but it doesn't actually copy the home address to the mailing address.

See the VBA code below.  I have between beginner and intermediate knowledge of VBA and intermediate knowledge of Access.

This might have something to do with the Me. controls and how I have them set up.  I've tried them a couple different ways, but I can't remember if any worked.

Thanks!
Private Sub btnCopyHomAdd_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MsgBox("Are you sure?", vbQuestion + vbYesNo) <> vbYes Then
Else
MaiAddress = Me.HomAddress
MaiCity = Me.HomCity
MaiState = Me.HomState
MaiZip = Me.HomZip
Me.Requery
End If
End Sub

Private Sub btnCopyIncAdd_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MsgBox("Are you sure?", vbQuestion + vbYesNo) <> vbYes Then
Else
HomAddress = Me.IncAddress
HomCity = Me.IncCity
HomState = Me.IncState
HomZip = Me.IncZip
Me.Requery
End If
End Sub

Open in new window

0
Comment
Question by:Ubertam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 33745097
use the Click event of the button

also, what are these?
MaiAddress
MaiCity
MaiState
MaiZip

are they textboxes in your form bound to fields of a table?
Private Sub btnCopyHomAdd_Click()
If MsgBox("Are you sure?", vbQuestion + vbYesNo) <> vbYes Then
Else
MaiAddress = Me.HomAddress
MaiCity = Me.HomCity
MaiState = Me.HomState
MaiZip = Me.HomZip
Me.Requery
End If
End Sub

Private Sub btnCopyIncAdd_Click()
If MsgBox("Are you sure?", vbQuestion + vbYesNo) <> vbYes Then
Else
HomAddress = Me.IncAddress
HomCity = Me.IncCity
HomState = Me.IncState
HomZip = Me.IncZip
Me.Requery
End If
End Sub

Open in new window

0
 
LVL 58
ID: 33745109
Some slight changes to the code:
Private Sub btnCopyHomAdd_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

If MsgBox("Are you sure?", vbQuestion + vbYesNo) = vbYes Then
Me.MaiAddress = Me.HomAddress
Me.MaiCity = Me.HomCity
Me.MaiState = Me.HomState
Me.MaiZip = Me.HomZip
Me.Requery
End If

End Sub

Private Sub btnCopyIncAdd_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

If MsgBox("Are you sure?", vbQuestion + vbYesNo) = vbYes Then
Me.HomAddress = Me.IncAddress
Me.HomCity = Me.IncCity
Me.HomState = Me.IncState
Me.HomZip = Me.IncZip
 Me.Requery
End If

 End Sub  
I would also move this code to the OnClick event of the buttons, rather then the mouse up.
JimD.
0
 
LVL 5

Author Comment

by:Ubertam
ID: 33746846
@Capricorn1: these are fields in the table, not the textboxes.  The textboxes are named txt_MaiAddress, txt_MaiCity, etc.

@JDettman: When I set Me.MaiAddress = Me.HomAddress and so forth, it throws an error that Me.MaiAddress doesn't exist.

Using Capricorn1's question about that they are, it hinted to me to set the VBA to the text boxes rather than the database fields.  This worked (see code below) to copy the addresses perfectly.

Now the only problem that still exists (it is now set to click) is that "Are you sure?" doesn't fully pop-up.  It is no longer slow (I can maximize Chrome and drag it away and the button is there without me waiting 10 seconds).  It's still a pop-under-ish bug.
Private Sub btnCopyHomAdd_Click()
If MsgBox("Are you sure?", vbQuestion + vbYesNo) <> vbYes Then
Else
txt_MaiAddress = txt_HomAddress
txt_MaiCity = txt_HomCity
txt_MaiState = txt_HomState
txt_MaiZip = txt_HomZip
Me.Requery
End If
End Sub

Private Sub btnCopyIncAdd_Click()
If MsgBox("Are you sure?", vbQuestion + vbYesNo) <> vbYes Then
Else
txt_HomAddress = txt_IncAddress
txt_HomCity = txt_IncCity
txt_HomState = txt_IncState
txt_HomZip = txt_IncZip
Me.Requery
End If
End Sub

Open in new window

0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 33746920
do a compact and repair
tools >database utilities > compact and repair..

then use this codes
Private Sub btnCopyHomAdd_Click()
If (MsgBox("Are you sure?", vbQuestion + vbYesNo)) = vbYes Then
txt_MaiAddress = txt_HomAddress
txt_MaiCity = txt_HomCity
txt_MaiState = txt_HomState
txt_MaiZip = txt_HomZip
Me.Requery
else
exit sub
End If
End Sub

Private Sub btnCopyIncAdd_Click()
If (MsgBox("Are you sure?", vbQuestion + vbYesNo)) = vbYes Then
txt_HomAddress = txt_IncAddress
txt_HomCity = txt_IncCity
txt_HomState = txt_IncState
txt_HomZip = txt_IncZip
Me.Requery
else
exit sub
End If
End Sub

Open in new window

0
 
LVL 5

Author Comment

by:Ubertam
ID: 33749551
That didn't do it.  I've attached the database.  See if it does it for you.  Thanks!
Flood-Cases-Shareable.accdb
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 33749817
test this

i created a copy of the Contact Details form and deleted the textbox txtDuplicatesWarning - we'll discuss the function of this later
Flood-Cases-Shareable.accdb
0
 
LVL 5

Author Comment

by:Ubertam
ID: 33758690
That is definitely the problem.

It was referencing [Contacts Extended] instead of [Contacts Extreme].  Changing that solved it.  I suppose it was doing a whole lot of cross-querying and running 10 miles when it needed a yard (or metre to any Brits reading this).

Yay!  It works.  Thanks for the help!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question