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.
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…
*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
Rey Obrero (Capricorn1)
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
mdstalla
ASKER
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
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.
in your db, do a compact and repair