Solved

Access 2013:  Sub Form Navigation Button VBA Codes are Replacing Eachother

Posted on 2013-12-23
10
2,004 Views
Last Modified: 2013-12-24
I have several (sub) forms that open from 2 Control Buttons at the bottom of each page (“Back” and “Next”).  I have embedded code into each button so that Access will display the appropriate (sub) forms if/when they are clicked.  The problem I’m facing is that the code I am writing into each button is replacing the code for other buttons.

For example:

When I type in the Code for the Next Button on Form 3, the Code for the Back Button on Form 1 is replaced.

Details:
Sub Form1 (Option Group—‘Offsite’ + Control Button—‘Next’) brings up Sub Form 3.  That is correct!

Sub Form3 (Control Button—‘Back’) brings up Sub Form 1.  That is correct!

Sub Form3 (Option Group—‘Yes’ + Control Button—‘Next’) does not work.  So I re-type the code into Sub Form3’s Control Button—‘Next.’

PROBLEM:  That code I just typed into Sub Form3’s Control Button—‘Next,’ is now appearing in Sub Form3’s Control Button—‘Back.’

Can any help me cure this problem?  I have attached the database; the “Navigation Form1” is the Parent Form with the Sub Forms.

Thanks.
Final-WUCAINS.accdb
0
Comment
Question by:mdstalla
  • 5
  • 5
10 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39737347
test this

in your db, do  a compact and repair
Final-WUCAINS-rev.accdb
0
 

Author Comment

by:mdstalla
ID: 39737385
Nope.  Didn't work.  I pressed that button after ever tiny step I took and codes are still being replaced.
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39737392
what do you mean being replaced?

here is the code from "Form3" that I've been testing and it stays intact..

Private Sub Back3_Click()
        DoCmd.BrowseTo acBrowseToForm, "Form1", "Navigation Form1.NavigationSubForm", , , acFormEdit

End Sub

Private Sub Next3_Click()
If Me.OG3 = 1 Then
        DoCmd.BrowseTo acBrowseToForm, "Form4", "Navigation Form1.NavigationSubForm", , , acFormEdit
    ElseIf Me.OG3 = 2 Then
        DoCmd.BrowseTo acBrowseToForm, "Form6", "Navigation Form1.NavigationSubForm", , , acFormEdit
    End If


End Sub
0
 

Author Comment

by:mdstalla
ID: 39737418
Okay.  Here’s what I do:

Form 1 (Control Button—‘Next’):

VBA Code Entered:
Private Sub Next1_Click()
If Me.OG1 = 1 Then
        DoCmd.BrowseTo acBrowseToForm, "Form2", "Navigation Form1.NavigationSubForm", , , acFormEdit
    ElseIf Me.OG1 = 2 Then
        DoCmd.BrowseTo acBrowseToForm, "Form3", "Navigation Form1.NavigationSubForm", , , acFormEdit
    End If
End Sub

*When operating in Navigation Form1/Form1… Yes, both of these codes work!  Okay, next form….

Form2 (Control Button—‘Back’):

VBA Code Entered:
Private Sub Back2_Click()
DoCmd.BrowseTo acBrowseToForm, "Form1", "Navigation Form1.NavigationSubForm", , , acFormEdit
End Sub

*When operating in Navigation Form1/Sub Form2 (‘Back Button’)… Yes, this code works!  Okay, let’s see how Navigation Form1/Sub Form2 (‘Next Button’) works…

Form2 (Control Button—‘Next’):

VBA Code Entered:
DoCmd.BrowseTo acBrowseToForm, "Form3", "Navigation Form1.NavigationSubForm", , , acFormEdit

*When operating in Navigation Form1/Form2… Yes, that code works!  Okay, next form…

Form3 (Control Button—‘Back’):

VBA Code Entered:
Private Sub Back3_Click()
DoCmd.BrowseTo acBrowseToForm, "Form1", "Navigation Form1.NavigationSubForm", , , acFormEdit
End Sub

*When operating in Navigation Form1/Form3… Yes, that code works!  But before we move on from here; for shits and giggles; let’s just make sure that previously programed Forms are operating as expected.  

Wait a minute!  

Form2 (Control Button—‘Back’), which was just coded with:
Private Sub Back2_Click()
DoCmd.BrowseTo acBrowseToForm, "Form1", "Navigation Form1.NavigationSubForm", , , acFormEdit
End Sub

Is no longer working, and is now coded with…

Private Sub Next2_Click()
DoCmd.BrowseTo acBrowseToForm, "Form3", "Navigation Form1.NavigationSubForm", , , acFormEdit
End Sub
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39738022
did you check, test the db I uploaded?

here it is again..


and, make sure that you hit the save icon after you tested your code
Final-WUCAINS-rev.accdb
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:mdstalla
ID: 39738692
Okay, I received the Database you sent me and reviewed the first 9 Sub Forms of the Navigation Form.  Here’s what I identified:

Most of the buttons worked (much better than I’ve been able to do on my end).  The only ones that didn’t work (and by that I mean you press the button and nothing happens) were:

Form 4 (Back Button)
Form 5 (Back Button)
Form 6 (Next Button)
Form 7 (Back Button)
Form 8 (Back Button)
Form 9 (Back Button)

So I went into each of these defective button myself, deleted the existing code (saved), and then typed in your codes (saved).  After these adjustments, I re-reviewed the first 9 Sub Forms of the Navigation Form.  

This is a list of the Buttons that don’t work this time (and by that I mean you press the button and nothing happens):

Form 4 (Next Button—Yes)    Access just decided to give it Form 4’s Back Button code
Form 4 (Next Button—No)  

Form 5 (Next Button)      Access just decided to give it Form 5’s Back Button code

Form 6 (Back Button)     Access just decided to give it Form 6’s Next Button code

Form 7 (Next Button—Yes)     Access just decided to give it Form 7’s Back Button code
Form 7 (Next Button—No)

Form 8 (Next Button—Yes)    Access just decided to give it Form 8’s Back Button code
Form 8 (Next Button—No)

Form 9 (Next Button)     Access just decided to give it Form 9’s Back Button code

I’ve attached the database you sent me with my updates to show the problem.  Any help you can give me to resolve this problem would very much appreciated.
Access-Trouble.accdb
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39738760
0
 

Author Comment

by:mdstalla
ID: 39738795
Okay, I got the database you sent me.  I tested Navigation Form1 (Sub Forms 1-9).  Every button functions, but there were a few that opened the wrong Sub Form.  Here’s the list of mis-coded buttons:

Sub Form 4 (Next Button—Yes)     Opens Sub Form 5 when it should open Sub Form 6
Sub Form 6 (Back)     Opens Sub Form 5 when it should open Sub Form 3
Sub Form 7 (Next Button—No)     Opens Sub Form 8 when it should open Sub Form 11
Sub Form 8 (Next Button—No)     Opens Sub Form 9 when it should open Sub Form 10

So again, I went into each mis-coded Button and changed the code (Delete existing code; Save; Input your codes, Save).  I re-tested Navigation Form1 (Sub Forms 1-9).  Here are the newly dysfunctional Buttons:

Sub Form 4 (Back Button)     Access decided to replace this code with Sub Form 4’s Next Button code  

Sub Form 6 (Next Button)     Access decided to replace this code with Sub Form 6’s Back Button code

Sub Form 7 (Back Button)     Access decided to replace this code with Sub Form 7’s Next Button code

Sub Form 8  (Back Button)     Access decided to replace this code with Sub Form 8’s Next Button code

The update Database is attached.
Access-Trouble2.accdb
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 39738841
i don't know exactly what you have been doing, but Access will not change the codes as you have described. I never knew of such behavior that Access will do.

try uninstalling your office or access, reboot your pc and do a clean full installation of office or access.
0
 

Author Closing Comment

by:mdstalla
ID: 39738872
I can’t figure it out either.  What I've done is literally start from scratch-- and re-wrote the entire database with all of the Forms.  If I run into this problem again I will try your suggestion and uninstall office.

Thanks for all of your help.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article will show you how to use shortcut menus in the Access run-time environment.
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

706 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now