Jump to content

12 posts in this topic

Posted

Hi guys, here is my problem, in vb I got a couple of forms and when I run the main form which has my buttons on it and when I want to click on any of the buttons the relevant form opens exactly how I want it, but on the forms that are open I have put a home button so when it is pressed it closes that page and goes back to main form..........well thats how I want it to work but it doesn't. This is what really happens....when a button is clicked it opens the relevant page which is ExhibitorForm.ShowDialog()and that sits on top of the main just how i want it and when I want to press the home button it closes that form and opens a new main form so I have 2 main forms.

Anybody got any ideas how I can resolve this?

Share this post


Link to post
Share on other sites

Posted

I do this in VBA should be the same

mainform
2ndform

so when you click 2ndform button you want


2ndform.show
mainform.hide

and when you click home you want

2ndform.hide
mainform.show

this will popup the same form

Share this post


Link to post
Share on other sites

Posted

I've done that and it puts the blue squiggle line under it and so I put ME.hide() and it closed it and done the same thing open another main, not sure if i am doing something right/wrong in the main to do this.

here is my code for my main form....

Public Class Mainmenu

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ExhibitorForm As New ExhibitorForm
ExhibitorForm.ShowDialog()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim visitosForm As New VisitorsForm
VisitorsForm.ShowDialog()


End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim PermanentStaff As New PermanentStaff
PermanentStaff.ShowDialog()





End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim AgencyStaff As New AgencySatff
AgencyStaff.ShowDialog()

End Sub
End Class

Share this post


Link to post
Share on other sites

Posted

Can you please press "code" when pasting code. I don't read code without the pretty colors!

Share this post


Link to post
Share on other sites

Posted

Just because you open a second form doesn't mean the main one has closed, so you don't actually have to do anything when you want to return to the first form - just close the second one.

Example:

You have "Form 1" open. You click "Button 1" on "Form 1" and this opens "Form 2." You click "Home" on "Form 2," which closes "Form 2." "Form 1" will still be open, so you need not do anything else.

Share this post


Link to post
Share on other sites

Posted

[quote name='Kalint' timestamp='1360346421' post='595510288']
Can you please press "code" when pasting code. I don't read code without the pretty colors!
[/quote]
Fixed that for you :)

[CODE]
Public Class Mainmenu

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ExhibitorForm As New ExhibitorForm
ExhibitorForm.ShowDialog()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim visitosForm As New VisitorsForm
VisitorsForm.ShowDialog()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim PermanentStaff As New PermanentStaff
PermanentStaff.ShowDialog()
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim AgencyStaff As New AgencySatff
AgencyStaff.ShowDialog()
End Sub

End Class [/CODE]

I suppose the reason why you're seeing a new main form when you click the "Home" button on your child forms (which code you haven't posted), is because the handler for that button is something like:

[CODE]
Dim MainForm As New MainForm
MainForm.Show()
[/CODE]

Obviously, this creates and shows a brand new main form, hence the observed behavior. What you could simply do in that handler is not create any form and close the current form, i.e. call Close(). This will let the parent form show once again.

Share this post


Link to post
Share on other sites

Posted

[quote name='Dr_Asik' timestamp='1360354208' post='595510514']
Fixed that for you :)

[CODE]
Public Class Mainmenu

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ExhibitorForm As New ExhibitorForm
ExhibitorForm.ShowDialog()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim visitosForm As New VisitorsForm
VisitorsForm.ShowDialog()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim PermanentStaff As New PermanentStaff
PermanentStaff.ShowDialog()
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim AgencyStaff As New AgencySatff
AgencyStaff.ShowDialog()
End Sub

End Class [/CODE]

I suppose the reason why you're seeing a new main form when you click the "Home" button on your child forms (which code you haven't posted), is because the handler for that button is something like:

[CODE]
Dim MainForm As New MainForm
MainForm.Show()
[/CODE]

Obviously, this creates and shows a brand new main form, hence the observed behavior. What you could simply do in that handler is not create any form and close the current form, i.e. call Close(). This will let the parent form show once again.
[/quote]

OHHH LOOK AT ALL THE COLORS!

Share this post


Link to post
Share on other sites

Posted

[quote name='Dr_Asik' timestamp='1360354208' post='595510514']
Fixed that for you :)

[CODE]
Public Class Mainmenu

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ExhibitorForm As New ExhibitorForm
ExhibitorForm.ShowDialog()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim visitosForm As New VisitorsForm
VisitorsForm.ShowDialog()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim PermanentStaff As New PermanentStaff
PermanentStaff.ShowDialog()
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim AgencyStaff As New AgencySatff
AgencyStaff.ShowDialog()
End Sub

End Class [/CODE]

I suppose the reason why you're seeing a new main form when you click the "Home" button on your child forms (which code you haven't posted), is because the handler for that button is something like:

[CODE]
Dim MainForm As New MainForm
MainForm.Show()
[/CODE]

Obviously, this creates and shows a brand new main form, hence the observed behavior. What you could simply do in that handler is not create any form and close the current form, i.e. call Close(). This will let the parent form show once again.
[/quote]

Sorry about the CODE thing, will try to do it next time.

Forgot aboutposting the code about the other form so here it is...

[CODE]

Public Class ExhibitorForm


Private Sub btnhome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhome.Click
Dim MainMenu As New Mainmenu
Me.Hide()
MainMenu.Show()


End Sub
End Class
[/CODE]

I have just changed it to close() and works.

Thanks for the help :D

Share this post


Link to post
Share on other sites

Posted

Hi guys, got another problem, I've put all my code in but it doesn't seem to work

This is the code for my button in the main menu.... once clicked it goes to my ExhibitorForm....Well it did before i put the code in on the ExhibitorForm now it throws up this message The 'Microsoft.ACE.OLEDB.12.0Data Source = Project.accdb' provider is not registered on the local machine. pointing at the con.open()

[CODE]

Public Class Mainmenu

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ExhibitorForm As New ExhibitorForm
ExhibitorForm.ShowDialog()

End Sub
[/CODE]


here is the code for my ExhibitorForm.....
[CODE]

Public Class ExhibitorForm
Dim inc As Integer
Dim MaxRows As Integer
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Dim cb As New OleDb.OleDbCommandBuilder(da)



Private Sub ExhibitorForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
dbProvider = "PROVIDER=Microsoft.ACE.OLEDB.12.0"
dbSource = "Data Source = Project.accdb"

con.ConnectionString = dbProvider & dbSource
con.Open()

sql = "SELECT * FROM tblExhibitorCompanies"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "Project")

MaxRows = ds.Tables("Project").Rows.Count
inc = -1
End Sub

Private Sub navigateRecords()
TxtCompID.Text = ds.Tables("Project").Rows(inc).Item(0)
TxtCompName.Text = ds.Tables("Project").Rows(inc).Item(1)
TxtCompAddress.Text = ds.Tables("Project").Rows(inc).Item(2)
TxtCompCity.Text = ds.Tables("Project").Rows(inc).Item(3)
TxtCompPhoneNum.Text = ds.Tables("Project").Rows(inc).Item(4)
TxtNumbStands.Text = ds.Tables("Project").Rows(inc).Item(5)
TxtPriceStands.Text = ds.Tables("Project").Rows(inc).Item(6)

End Sub


Private Sub btnprevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprevious.Click
If inc > 0 Then
inc = inc - 1
navigateRecords()
ElseIf inc = -1 Then
MsgBox("No Records Yet")

ElseIf inc = 0 Then

MsgBox("First Record")
End If
End Sub

Private Sub btnnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnext.Click
If inc <> MaxRows - 1 Then
inc = inc + 1
Else
MsgBox("No More Rows")
End If
End Sub

Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click

Dim cb As New OleDb.OleDbCommandBuilder(da)

ds.Tables("Project").Rows(inc).Item(0) = TxtCompID.Text
ds.Tables("Project").Rows(inc).Item(1) = TxtCompName.Text
ds.Tables("Project").Rows(inc).Item(2) = TxtCompAddress.Text
ds.Tables("Project").Rows(inc).Item(3) = TxtCompCity.Text
ds.Tables("Project").Rows(inc).Item(4) = TxtCompPhoneNum.Text
ds.Tables("Project").Rows(inc).Item(5) = TxtNumbStands.Text
ds.Tables("Project").Rows(inc).Item(6) = TxtPriceStands.Text



da.Update(ds, "AddressBook")

MsgBox("Data Updated")

If inc <> -1 Then

End If

Dim dsNewRow As DataRow

dsNewRow = ds.Tables("Project").NewRow()

dsNewRow.Item("CompanyID") = TxtCompID.Text
dsNewRow.Item("CompanyName") = TxtCompName.Text
dsNewRow.Item("CompanyAddress") = TxtCompAddress.Text
dsNewRow.Item("City") = TxtCompCity.Text
dsNewRow.Item("TelephoneNumber") = TxtCompPhoneNum.Text
dsNewRow.Item("NumberofStands") = TxtNumbStands.Text
dsNewRow.Item("PriceofStands") = TxtPriceStands.Text



ds.Tables("AddressBook").Rows.Add(dsNewRow)

da.Update(ds, "AddressBook")

MsgBox("New Record added to the Database")

btnsave.Enabled = False
btnadd.Enabled = True
btnedit.Enabled = True
btndelete.Enabled = True

End Sub

Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
btnsave.Enabled = True
btnadd.Enabled = False
btnedit.Enabled = False
btndelete.Enabled = False

TxtCompID.Clear()
TxtCompName.Clear()
TxtCompAddress.Clear()
TxtCompCity.Clear()
TxtCompPhoneNum.Clear()
TxtNumbStands.Clear()
TxtPriceStands.Clear()


End Sub

Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
Dim cb As New OleDb.OleDbCommandBuilder(da)

If MessageBox.Show("Please confirm you want to Delete this Record?", "Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.No Then
MsgBox("Operation Canceled")
Exit Sub

End If
ds.Tables("Project").Rows(inc).Delete()
MaxRows = MaxRows - 1
inc = 0
navigateRecords()
da.Update(ds, "Project")
End Sub
End Class

[/CODE]



Any Ideas guys?

Share this post


Link to post
Share on other sites

Posted

[quote name='puppet_master' timestamp='1360676942' post='595516920']
Hi guys, got another problem, I've put all my code in but it doesn't seem to work

This is the code for my button in the main menu.... once clicked it goes to my ExhibitorForm....Well it did before i put the code in on the ExhibitorForm now it throws up this message The 'Microsoft.ACE.OLEDB.12.0Data Source = Project.accdb' provider is not registered on the local machine. pointing at the con.open()

[CODE]

Public Class Mainmenu

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ExhibitorForm As New ExhibitorForm
ExhibitorForm.ShowDialog()

End Sub
[/CODE]


here is the code for my ExhibitorForm.....
[CODE]
Private Sub ExhibitorForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
dbProvider = "PROVIDER=Microsoft.ACE.OLEDB.12.0"
dbSource = "Data Source = Project.accdb"

con.ConnectionString = dbProvider & dbSource
con.Open()
[/CODE]

Any Ideas guys?
[/quote]
Yes... Quite simply when you're combining the strings the '12.0' and the 'Data' are being combined into '12.0Data' because you're neglecting a required separator ';'.

Share this post


Link to post
Share on other sites

Posted

I dont know what you mean......do you mean i should write it as ..........ACE.OLEDB.12.0DATA?

Share this post


Link to post
Share on other sites

Posted

[quote name='puppet_master' timestamp='1360794270' post='595520094']
I dont know what you mean......do you mean i should write it as ..........ACE.OLEDB.12.0DATA?
[/quote]

No I mean you're missing the ';' separator between the provider and data source declarations when you combine them...
[CODE]
' as you can see below you have two variables one for provider, one for source '
dbProvider = "PROVIDER=Microsoft.ACE.OLEDB.12.0"
dbSource = "Data Source = Project.accdb"

'here you are combining them into a connection string, with the ; separator, you end up with an invalid connection string'
con.ConnectionString = dbProvider & dbSource
'Simply add ; to the end of the provider string as such'
dbProvider = "PROVIDER=Microsoft.ACE.OLEDB.12.0;"
[/CODE]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.