Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MS Access event assignmts

Posted on 2014-11-25
13
Medium Priority
?
218 Views
Last Modified: 2014-11-25
Have 4 buttons same code for retieving word doc and retrival works fine
However, event procedure doesn't save when assigning to different buttons
Is this an incorrect prcedure? Saving ode to a command button seems intuitive but when moving to recording to the following buttons seems to erase the event procedure on the previous button.
any suggstions helpful
0
Comment
Question by:gksewell
[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
  • 6
  • 5
  • 2
13 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40464435
have you done a compact and repair?

why 4 buttons doing the same thing?
0
 

Author Comment

by:gksewell
ID: 40464507
each button pulls up a differnet word template for data merge
just redid event assignments to each button but only the last button retains the event procedure.
yes did compact & repair
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40464623
how did you do "event assignments" ?

is your form in design view when you were doing the event assignments?
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:gksewell
ID: 40464653
yes always in design view when configuring
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40464676
can you upload a copy of your db.
0
 

Author Comment

by:gksewell
ID: 40464789
these are the 4 events for the 4 cmd buttons

Private Sub Command106_Click()

Dim mydoc As String
mydoc = "C:\Users\sewellg\Desktop\New Router Config Tool 2\DC2 VPN Router.docx"
Application.FollowHyperlink mydoc

End Sub

Private Sub Command107_Click()

Dim mydoc As String
mydoc = "C:\Users\sewellg\Desktop\New Router Config Tool 2\DC2 VPN Tunnel.docx"
Application.FollowHyperlink mydoc

End Sub

Private Sub Command108_Click()

Dim mydoc As String
mydoc = "C:\Users\sewellg\Desktop\New Router Config Tool 2\DC1 VPN Router.docx"
Application.FollowHyperlink mydoc

End Sub

Private Sub Command109_Click()

Dim mydoc As String
mydoc = "C:\Users\sewellg\Desktop\New Router Config Tool 2\DC1 VPN Tunnel.docx"
Application.FollowHyperlink mydoc

End Sub
Router-Builds1.accdb
0
 
LVL 26

Accepted Solution

by:
Nick67 earned 2000 total points
ID: 40464857
It is not enough to add code in the code window.
Yes, in the code window, you can click the object drop down and get the event for a different control
You can copy a procedure

 Private Sub Command109_Click()
 Dim mydoc As String
 mydoc = "C:\Users\sewellg\Desktop\New Router Config Tool 2\DC1 VPN Tunnel.docx"
 Application.FollowHyperlink mydoc
 End Sub


Paste it can change it's name

Private Sub Command110_Click()
 Dim mydoc As String
 mydoc = "C:\Users\sewellg\Desktop\New Router Config Tool 2\DC1 VPN Tunnel.docx"
 Application.FollowHyperlink mydoc
 End Sub


But until you've gone in the Design View | Properties window and set the Click Event to [Event Procedure] that control isn't going to use the event.

Two stages!
Assign the control in the Design view [Event Procedure] for the appropriate event
Code the event in the Window.

I've fixed your sample using Access 2013
Router-Builds1.accdb
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40464885
first open the form that have your 4 command buttons

select one command button, then hit F4
select the Event Tab and look for the On Click event
click the drop down arrow and select [Event Procedure]
then click the (...) this will take you to the VBA window..
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40464907
see this
x
0
 

Author Comment

by:gksewell
ID: 40464939
Only the 1st button worked that is what I had to start with
I was following your procedure since yesterday a few dozen times and when one proceeds to the next button it erases previous procedure for previous button even saving and geting out and back into DB
Your db did show the Event click process in each property box but if I use the .... then it starts a new instance.
Appreciate your patience.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40464958
< if I use the .... then it starts a new instance.>
this instance is the one that you must use..

also, it will be a lot easier for you to read your codes if you will give your controls, command buttons in this case, a meaningful name not command1, command 2 etc...
0
 
LVL 26

Expert Comment

by:Nick67
ID: 40464969
Ok here is your sample again.
Each button is wired up
Each button has identical code in it
The code survived a compact & repair.
You will need to alter the code to match the filenames you actually want to open.

Unlike VB6 and VB.NET, each control MUST have it's own event handler.
Stuff like

Private Sub OpenFile() Handles command106_click(),command107_click() ...

is not valid.

You have 4 controls
Each is wired up with a click [Event Procedure]
Each event exists in the code module.
Check the sample.

With accdb files EE is broken at the moment.
You must right-click the file and Choose Save As.
Then Choose All Files
And then give it an .accdb ending
Router-Builds1.accdb
0
 

Author Closing Comment

by:gksewell
ID: 40465153
thanks for all the professional help and your Patience.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
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 …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

670 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