Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to VB.net and I have question regarding an Access database. The database (Herbalist.Settings) has a field named DefPage which identifies the VB.net 2019 application's startup tabpage.

When I am loading the application (FrmMain.vb), I want to open the correct tabpage as set in the database.

I have a function called GetHome() that gets the correct tabpage but it calls on a combobox in another form named DlgSettings.vb

I have tried the following code that does not work because DlgSettings is not open (correct?):

I don't where to go from here.

What I have tried:

DlgSettings code:

VB
    End Function
    Public Function CloseAllTabs()
        With FrmMain
            .TabControl1.TabPages.Remove(.TabPage1)
            .TabControl1.TabPages.Remove(.TabPage2)
            .TabControl1.TabPages.Remove(.TabPage3)
            .TabControl1.TabPages.Remove(.TabPage4)
            .TabControl1.TabPages.Remove(.TabPage5)
            .TabControl1.TabPages.Remove(.TabPage6)
            .TabControl1.TabPages.Remove(.TabPage7)
            .TabControl1.TabPages.Remove(.TabPage8)
            .TabControl1.TabPages.Remove(.TabPage9)
            .TabControl1.TabPages.Remove(.TabPage10)
            .TabControl1.TabPages.Remove(.TabPage13)
            .TabControl1.TabPages.Remove(.TabPage14)
            .TabControl1.TabPages.Remove(.TabPage22)
        End With
        Return True
    End Function

    Public Function ShowAllButtons()
        With FrmMain
            .ToolStripButton1.Enabled = True
            .ToolStripButton2.Enabled = True
            .ToolStripButton3.Enabled = True
            .ToolStripButton4.Enabled = True
            .ToolStripButton5.Enabled = True
            .ToolStripButton6.Enabled = True
            .ToolStripButton7.Enabled = True
            .ToolStripButton8.Enabled = True
            .ToolStripButton9.Enabled = True
            .ToolStripButton10.Enabled = True
            .ToolStripButton11.Enabled = True
            .DefinitionsToolStripMenuItem.Enabled = True
        End With
        Return True
    End Function

    Public Function CloseAllTabsExcept(tp As TabPage)
        With FrmMain
            CloseAllTabs()
            .TabControl1.TabPages.Add(tp)
        End With
        Return True
    End Function

Public Function GetHome(page As ComboBox)
        With FrmMain
            Select Case page.Text
                Case "Home"
                    CloseAllTabsExcept(.TabPage1)
                Case "Herbs"
                    CloseAllTabsExcept(.TabPage2)
                Case "Herbal Recipes"
                    CloseAllTabsExcept(.TabPage3)
                Case "Essential Oils"
                    CloseAllTabsExcept(.TabPage4)
                Case "EO Blending"
                    CloseAllTabsExcept(.TabPage17)
                Case "EO Blends"
                    CloseAllTabsExcept(.TabPage5)
                Case "Magic Uses"
                    CloseAllTabsExcept(.TabPage8)
                Case "Magical Formulas"
                    CloseAllTabsExcept(.TabPage7)
            End Select
        End With
        Return True
    End Function

FrmMain Code:

GetHome(DlgSettings.ComboBox2)
Posted
Updated 14-Aug-22 1:06am
Comments
Richard MacCutchan 14-Aug-22 3:15am    
Your question asks about getting a value from a database, but the code is trying to get it from a dialog's combobox. However, your main problem is that you must run the dialog form (ShowDialog) in order to get any values from it.
[no name] 14-Aug-22 7:14am    
Richard, you are correct. I can get the data from the database in the DlgSettings form. That is not the issue.

I need to get the information from the database when FrmMain loads so that the default tab page can be displayed without opening the settings dialog window.

I am sorry that I was not more clear. The database contains the name of the tabpage to open. i.e. the 'Home' tabpage, or the 'Herbs' tabpage, or the 'Essential Oils' tabpage.

I was trying to access the data from the combobox because it was the only way I knew how to do it. Thus my question to this forum.

Thanks for your patience with my ignorance.
Richard MacCutchan 14-Aug-22 7:20am    
If you need to get it from the database, then I assume you already have the code to store the information. So look at that and you should easily be able to work out what you need to read it back.
[no name] 14-Aug-22 7:30am    
No, I don't have the code. I assigned the combobox value using a bindingsource.

Please, as I said I am new to VB.net and have not had any training using it. That is why I have asked my question on this forum. I have yet to find it elsewhere on the internet (my only resource to learn the VB syntax)

I am sorry that I am not making myself clearer on this.

Again, thank you for your time.
Richard MacCutchan 14-Aug-22 9:46am    
I am sorry but now I am very confused. If you do not understand the basics of VB.NET then you need to stop what you are doing.
What you do need to do is:
1. Learn the basics of VB.NET, including the general syntax and the most common classes.
2. Then you need to learn how to use Windows Forms, starting with a single form example. Follw that with using child forms and dialogs.
3. Then you need to learn ADO.NET with emphasis on using an Access database.

And at each step you need to practice what you have learnt so you understand it fully.

Trying to learn all these things at the same time will just lead to more and more confusion.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900