Link to home
Start Free TrialLog in
Avatar of mdstalla
mdstalla

asked on

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

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
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

test this

in your db, do  a compact and repair
Final-WUCAINS-rev.accdb
Avatar of mdstalla
mdstalla

ASKER

Nope.  Didn't work.  I pressed that button after ever tiny step I took and codes are still being replaced.
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
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
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
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
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
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.