I have a form (QuoteForm) that has a tab control within it.
It currently has 2 tabs, but what I am trying to do (and not succeeding very well) is to add a button that when clicked, will add a new tab to the control. Currently the button opens another form that will allow you to enter the desired name for the tab you are trying to create. The button on that form (named simply "add sheet") is what should add the new tab with the name you just entered.
The problem I have run into, is it keeps adding tabs to the sheet over and over with every click. I know this is where some will go "But that is what you wanted isn't it?" Yes, but the new problem this creates is my form keeps getting more and more tabs even when I want to open a "fresh" form. It also causes problems due to the tabs number increasing with every addition, so in my testing the code eventually loses track of the tab number (say if I deleted all the previous tabs to "start over") and then throws an error.
The code I am currently using is:
Option Compare Database
Private Sub Command2_Click()
On Error GoTo ErrorHandler
DoCmd.Close acForm, "QuoteForm", acSaveYes
DoCmd.OpenForm "QuoteForm", acDesign, , , , acHidden
Forms("QuoteForm")("TabCtl43").Pages.Add
Dim pageNumber As Integer
pageNumber = Forms("QuoteForm")("TabCtl43").Pages.Count
Forms("QuoteForm")("TabCtl43").Pages.Item(pageNumber - 1).Name = "Some Name" & pageNumber
Forms("QuoteForm")("TabCtl43").Pages.Item(pageNumber - 1).Caption = "Some Caption"
DoCmd.Close acForm, "QuoteForm", acSaveYes
DoCmd.OpenForm "QuoteForm", acNormal
DoCmd.Close acForm, Me.Name, acSaveNo
Exit_Here:
Exit Sub
ErrorHandler:
MsgBox "Error: " & Err.Description
Resume Exit_Here
End Sub
I also dont like the fact that the screen flickers when executing this command (because it has to go into design view and add the tab real quick then back to form view), but from what I have researched, that isnt really avoidable.
It currently has 2 tabs, but what I am trying to do (and not succeeding very well) is to add a button that when clicked, will add a new tab to the control. Currently the button opens another form that will allow you to enter the desired name for the tab you are trying to create. The button on that form (named simply "add sheet") is what should add the new tab with the name you just entered.
The problem I have run into, is it keeps adding tabs to the sheet over and over with every click. I know this is where some will go "But that is what you wanted isn't it?" Yes, but the new problem this creates is my form keeps getting more and more tabs even when I want to open a "fresh" form. It also causes problems due to the tabs number increasing with every addition, so in my testing the code eventually loses track of the tab number (say if I deleted all the previous tabs to "start over") and then throws an error.
The code I am currently using is:
Option Compare Database
Private Sub Command2_Click()
On Error GoTo ErrorHandler
DoCmd.Close acForm, "QuoteForm", acSaveYes
DoCmd.OpenForm "QuoteForm", acDesign, , , , acHidden
Forms("QuoteForm")("TabCtl43").Pages.Add
Dim pageNumber As Integer
pageNumber = Forms("QuoteForm")("TabCtl43").Pages.Count
Forms("QuoteForm")("TabCtl43").Pages.Item(pageNumber - 1).Name = "Some Name" & pageNumber
Forms("QuoteForm")("TabCtl43").Pages.Item(pageNumber - 1).Caption = "Some Caption"
DoCmd.Close acForm, "QuoteForm", acSaveYes
DoCmd.OpenForm "QuoteForm", acNormal
DoCmd.Close acForm, Me.Name, acSaveNo
Exit_Here:
Exit Sub
ErrorHandler:
MsgBox "Error: " & Err.Description
Resume Exit_Here
End Sub
I also dont like the fact that the screen flickers when executing this command (because it has to go into design view and add the tab real quick then back to form view), but from what I have researched, that isnt really avoidable.