Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Buttons VB don't work

visual basic 4 / 5 / 6 buttons access linking visual basics

  • Please log in to reply
9 replies to this topic

#1 Jeroen

Jeroen

    CC Lurker

  • New Member
  • Pip
  • 7 posts
  • Programming Language:Java, (Visual) Basic
  • Learning:(Visual) Basic

Posted 20 September 2012 - 03:30 AM

Dear all,

This is my first time on the forum and I'm creating a visual basic GUI in which I can enter certain data and the entered data can and will be saved in the MS access database.

I created my VB program and linked it with my MS access database, the good thing is, it will load my first row of the database, but unfortunately it doesn't show the following rows. Also my buttons like save, add,... don't Work. Can someone have a quick look and tell me what I'm doing wrong?

Furthermore is it possible to create a button, which will save a form in my MS access database or is the easiest way to create another new form in VB and print this form?

Kind regards,

Jeroen

Since it is unable for me to attach files, I'll add my code in this way!


Class MainWindow

	Private testdatabaseData As New testdatabaseDataSet
	Private tatestdatabase As New testdatabaseDataSetTableAdapters.testdatabaseTableAdapter
	Private taManager As New testdatabaseDataSetTableAdapters.TableAdapterManager
	Private View As CollectionView

	Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
		Me.tatestdatabase.Fill(Me.testdatabaseData.testdatabase)

		Me.DataContext = Me.testdatabaseData.testdatabase

		Me.taManager.testdatabaseTableAdapter = tatestdatabase

		Me.DataContext = Me.testdatabaseData.testdatabase

		Me.View = CType(CollectionViewSource.GetDefaultView(Me.testdatabaseData.testdatabase), CollectionView)

		Dim TestdatabaseDataSet As WpfDataBase.testdatabaseDataSet = CType(Me.FindResource("TestdatabaseDataSet"), WpfDataBase.testdatabaseDataSet)
		'Load data into the table testdatabase. You can modify this code as needed.
		Dim TestdatabaseDataSettestdatabaseTableAdapter As WpfDataBase.testdatabaseDataSetTableAdapters.testdatabaseTableAdapter = New WpfDataBase.testdatabaseDataSetTableAdapters.testdatabaseTableAdapter()
		TestdatabaseDataSettestdatabaseTableAdapter.Fill(TestdatabaseDataSet.testdatabase)
		Dim TestdatabaseViewSource As System.Windows.Data.CollectionViewSource = CType(Me.FindResource("TestdatabaseViewSource"), System.Windows.Data.CollectionViewSource)
		TestdatabaseViewSource.View.MoveCurrentToFirst()
	End Sub

	Private Sub cmdfirst_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles cmdfirst.Click
		Me.View.MoveCurrentToFirst()

	End Sub

	Private Sub btnprevious_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles cmdprevious.Click
		If Me.View.CurrentPosition > 0 Then
			Me.View.MoveCurrentToPrevious()
		End If

	End Sub

	Private Sub cmdnext_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles cmdnext.Click
		If Me.View.CurrentPosition < Me.View.Count - 1 Then
			Me.View.MoveCurrentToNext()
		End If

	End Sub

	Private Sub cmdLast_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles cmdLast.Click
		Me.View.MoveCurrentToLast()
	End Sub

	Private Sub BtnDelete_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles cmdDelete.Click
		If Me.View.CurrentPosition > -1 Then
			Dim row = CType(Me.View.CurrentItem, System.Data.DataRowView).Row
			row.Delete()
		End If
	End Sub

	Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles cmdAdd.Click
		If Not Me.testdatabaseData.HasErrors Then
			Dim row = Me.testdatabaseData.testdatabase.NewtestdatabaseRow
			row.Naam = ""
			Me.testdatabaseData.testdatabase.AddtestdatabaseRow(row)
			Me.View.MoveCurrentToLast()
		End If
	End Sub

	Private Sub cmdRevert_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles cmdRevert.Click
		If Me.testdatabaseData.HasChanges Then
			If MessageBox.Show("Are you sure you want to lose all your changes?", Me.Title, MessageBoxButton.YesNo) = MessageBoxResult.Yes Then
				Me.testdatabaseData.RejectChanges()
			End If
		End If

	End Sub

	Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles cmdSave.Click
		Try
			If Me.testdatabaseData.HasErrors Then
				MsgBox("Please correct the errors first")
			Else
				If Me.testdatabaseData.HasChanges Then
					If Me.taManager.UpdateAll(Me.testdatabaseData) > 0 Then
						MsgBox("Saved.")
					End If
				End If
			End If

		Catch ex As Exception
			MsgBox(ex.ToString)

		End Try

	End Sub

End Class

Partial Class testdatabaseDataSet
	Partial Class testdatabaseDataTable

		Private Sub CheckNaam(ByVal row As testdatabaseRow)
			If row.IsNull("Naam") OrElse row.Naam = "" Then
				row.SetColumnError(Me.NaamColumn, "Please enter a naam")

			Else
				row.SetColumnError(Me.NaamColumn, "")
			End If
		End Sub

		Private Sub testdatabaseDataTable_Columnchanged(ByVal sender As Object, ByVal e As System.Data.DataColumnChangeEventArgs) Handles Me.ColumnChanged
			If e.Column Is Me.NaamColumn Then
				Me.CheckNaam(CType(e.Row, testdatabaseRow))
			End If

		End Sub

		Private Sub testdatabaseDataTable_TableNewRow(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs) Handles Me.TableNewRow
			Me.CheckNaam(CType(e.Row, testdatabaseRow))
		End Sub



	End Class

End Class


:Class="MainWindow"
	xmlns="[url="http://schemas.microsoft.com/winfx/2006/xaml/presentation"]http://schemas.micro...l/presentation"[/url]
	xmlns:x="[url="http://schemas.microsoft.com/winfx/2006/xaml"]http://schemas.micro...infx/2006/xaml"[/url]
	Title="MainWindow" Height="406" Width="814" xmlns:my="clr-namespace:WpfDataBase">
	<window.Resources>
		<my:testdatabaseDataSet x:Key="TestdatabaseDataSet" />
		<CollectionViewSource x:Key="TestdatabaseViewSource" Source="{Binding Path=testdatabase, Source={StaticResource TestdatabaseDataSet}}" />
	</window.Resources>
	<Grid Height="369" Width="770">
		<Grid.RowDefinitions>
			<RowDefinition Height="66*" />
			<RowDefinition Height="303*" />
		</Grid.RowDefinitions>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="200*" />
			<ColumnDefinition Width="200*" />
		</Grid.ColumnDefinitions>
		<Button Content="Save" Grid.Column="1" Height="23" HorizontalAlignment="Left" Margin="237,0,0,0" Name="cmdSave" VerticalAlignment="Top" Width="75" />
		<Button Content="Revert" HorizontalAlignment="Right" Margin="0,0,0,43" Name="cmdRevert" Width="75" Grid.Column="1" />
		<Button Content="Add" Height="23" HorizontalAlignment="Left" Margin="164,0,0,0" Name="cmdAdd" VerticalAlignment="Top" Width="75" Grid.Column="1" />
		<Button Content="Delete" HorizontalAlignment="Left" Margin="112,0,0,43" Name="cmdDelete" Width="55" Grid.Column="1" BorderBrush="#FFFA0000" BorderThickness="3" />
		<Button Content="|&lt;" Height="23" HorizontalAlignment="Left" Name="cmdfirst" VerticalAlignment="Top" Width="75" />
		<Button Content="&lt;" Height="23" HorizontalAlignment="Left" Margin="73,0,0,0" Name="cmdprevious" VerticalAlignment="Top" Width="75" />
		<Button Content="&gt;" Height="23" HorizontalAlignment="Left" Margin="146,0,0,0" Name="cmdnext" VerticalAlignment="Top" Width="75" />
		<Button Content="&gt;|" Height="23" HorizontalAlignment="Right" Margin="0,0,91,0" Name="cmdLast" VerticalAlignment="Top" Width="75" />
		<StackPanel Grid.Row="1" Height="303" HorizontalAlignment="Left" Margin="12,0,0,0" Name="StackPanel1" VerticalAlignment="Top" Width="369">
			<Label Content="Naam" Height="28" Name="Label1" />
			<Label Content="Voornaam" Height="28" Name="Label2" />
			<Label Content="Euros op bankrekening" Height="28" Name="Label3" />
		</StackPanel>
		<StackPanel Grid.Column="1" Grid.Row="1" Height="300" HorizontalAlignment="Left" Name="StackPanel2" VerticalAlignment="Top" Width="385" DataContext="{StaticResource TestdatabaseViewSource}">
			<TextBox Height="28" Name="txtnaam" Width="120" Text="{Binding Path=Naam, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationerror=true, ValidatesOnDataErrors=True}" IsManipulationEnabled="True" />
			<TextBox Height="28" Name="txtvoornaam" Width="120" Text="{Binding Path=Voornaam, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationerror=true, ValidatesOnDataErrors=True}" IsManipulationEnabled="True" />
			<TextBox Height="28" Name="txteurosopbankrekening" Width="120" Text="{Binding Path=Euro\'s op rekening, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationerror=true, ValidatesOnDataErrors=True}" IsManipulationEnabled="True" />
		</StackPanel>
	</Grid>
</Window>

Edited by Roger, 20 September 2012 - 03:56 PM.
added code tags

  • 0

#2 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 20 September 2012 - 05:46 AM

You better zip all your files (including database) and attach it. This way it will help us to debug your code and find error in it.
  • 0

#3 Jeroen

Jeroen

    CC Lurker

  • New Member
  • Pip
  • 7 posts
  • Programming Language:Java, (Visual) Basic
  • Learning:(Visual) Basic

Posted 20 September 2012 - 06:17 AM

Ok, I'll do that, thank you!
  • 0

#4 Jeroen

Jeroen

    CC Lurker

  • New Member
  • Pip
  • 7 posts
  • Programming Language:Java, (Visual) Basic
  • Learning:(Visual) Basic

Posted 20 September 2012 - 06:52 AM

normally, this is everything I have!

I hope to have an answer soon and see whether I'm doing a good job, the database is just to practice.

Attached Files


  • 0

#5 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 20 September 2012 - 06:58 AM

normally, this is everything I have!

I hope to have an answer soon and see whether I'm doing a good job, the database is just to practice.

I don't see any attachment in your reply or in your original post.
  • 0

#6 Jeroen

Jeroen

    CC Lurker

  • New Member
  • Pip
  • 7 posts
  • Programming Language:Java, (Visual) Basic
  • Learning:(Visual) Basic

Posted 20 September 2012 - 07:00 AM

Thank you for the quick answer, I added it in my previous post
  • 0

#7 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 20 September 2012 - 07:03 AM

Thank you for the quick answer, I added it in my previous post

The attached zip file does not contain any database file. Well, the solution file has a link to the database but the actually MS Access database file is missing.
  • 0

#8 Jeroen

Jeroen

    CC Lurker

  • New Member
  • Pip
  • 7 posts
  • Programming Language:Java, (Visual) Basic
  • Learning:(Visual) Basic

Posted 20 September 2012 - 11:29 PM

A little bit later than expected

Attached Files


  • 0

#9 Jeroen

Jeroen

    CC Lurker

  • New Member
  • Pip
  • 7 posts
  • Programming Language:Java, (Visual) Basic
  • Learning:(Visual) Basic

Posted 23 September 2012 - 11:24 PM

Does someone have time to take a look at it? Because I tried to debug it this weekend, but I couldn't find the problem.
  • 0

#10 Jeroen

Jeroen

    CC Lurker

  • New Member
  • Pip
  • 7 posts
  • Programming Language:Java, (Visual) Basic
  • Learning:(Visual) Basic

Posted 28 September 2012 - 01:24 AM

Thank you for the help guys!
  • 0





Also tagged with one or more of these keywords: visual basic 4 / 5 / 6, buttons, access linking, visual basics

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download