Dear all,
Try
connection.ConnectionString ="PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=Z:\Corporate Reporting\2014_15\Corporate\QuarterlyReporting.accdb"
connection.Open()
'--For the text boxes--
sql1 ="SELECT * FROM Projects_Application"
DataAdapter =New OleDb.OleDbDataAdapter(sql1, connection)
DataAdapter.Fill(DataSet,"Projects")
'--For the combo--
sql2 ="SELECT ProjectID FROM Projects_Application ORDER BY ProjectID"
Dim cm AsNew OleDb.OleDbCommand(sql2, connection)
Dim dr As OleDb.OleDbDataReader = cm.ExecuteReader
While dr.Read
cmbSearch.Items.Add(dr(0).ToString)
EndWhile
dr.Close()
connection.Close()
MaxRows = DataSet.Tables("Projects").Rows.Count
inc =-1
Catch ex As Exception
MsgBox(ex.Message)
EndTry
EndSub
PrivateSub NavigateRecords()
txtProjectName.Text = DataSet.Tables("Projects").Rows(inc).Item(0)
txtProjectID.Text = DataSet.Tables("Projects").Rows(inc).Item(1)
txtProjectManager.Text = DataSet.Tables("Projects").Rows(inc).Item(2)
EndSub
PrivateSub btnNext_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles btnNext.Click
If inc <>(MaxRows -1)Then
inc = inc +1
NavigateRecords()
EndIf
EndSub
PrivateSub btnPrevious_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles btnPrevious.Click
If inc >0Then
inc = inc -1
NavigateRecords()
EndIf
EndSub
PrivateSub btnFirst_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles btnFirst.Click
If inc >0Then
inc =0
NavigateRecords()
EndIf
EndSub
PrivateSub bntLastR_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles bntLastR.Click
If inc <>(MaxRows -1)Then
inc = MaxRows -1
NavigateRecords()
EndIf
EndSub
PrivateSub btnSearch_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles btnSearch.Click
??????
EndSub
I have started to build the application where I can navigate through a table in Access and bring in three text boxes the ProjectID, ProjectName and ProjectManager. I have also added 4 buttons (MoveNext, MoveBack, MoveFirstRecord and MoveLastRecord) that work.At the moment, when I load the application I am able to navigate through the records and display in the text boxes the Project Name, Project ID and Project Manager. I can also move next, move back, move to the first record and move the last one without problems.I have also managed to add a combo that displays all the Projects ID, which are always unique.What I need to do is, by choosing a Project ID from that combo box and then clicking on a new button called "Search Project", to fill the text boxes with the appropriate information for the Project ID chosen in the combo.I am quite lost and I don't know to approach this in a efficiente way.
This is the code I currently have:
PrivateSub Form2_Load(ByVal sender AsObject,ByVal e As System.EventArgs)HandlesMe.LoadThis is the code I currently have:
Public Class Form2
Dim connection As New OleDb.OleDbConnection
Dim DataSet As New DataSet
Dim DataAdapter As OleDb.OleDbDataAdapter
Dim sql1 As String
Dim sql2 As String
Dim inc As Integer
Dim MaxRows As Integer
Dim connection As New OleDb.OleDbConnection
Dim DataSet As New DataSet
Dim DataAdapter As OleDb.OleDbDataAdapter
Dim sql1 As String
Dim sql2 As String
Dim inc As Integer
Dim MaxRows As Integer
Try
connection.ConnectionString ="PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=Z:\Corporate Reporting\2014_15\Corporate\QuarterlyReporting.accdb"
connection.Open()
'--For the text boxes--
sql1 ="SELECT * FROM Projects_Application"
DataAdapter =New OleDb.OleDbDataAdapter(sql1, connection)
DataAdapter.Fill(DataSet,"Projects")
'--For the combo--
sql2 ="SELECT ProjectID FROM Projects_Application ORDER BY ProjectID"
Dim cm AsNew OleDb.OleDbCommand(sql2, connection)
Dim dr As OleDb.OleDbDataReader = cm.ExecuteReader
While dr.Read
cmbSearch.Items.Add(dr(0).ToString)
EndWhile
dr.Close()
connection.Close()
MaxRows = DataSet.Tables("Projects").Rows.Count
inc =-1
Catch ex As Exception
MsgBox(ex.Message)
EndTry
EndSub
PrivateSub NavigateRecords()
txtProjectName.Text = DataSet.Tables("Projects").Rows(inc).Item(0)
txtProjectID.Text = DataSet.Tables("Projects").Rows(inc).Item(1)
txtProjectManager.Text = DataSet.Tables("Projects").Rows(inc).Item(2)
EndSub
PrivateSub btnNext_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles btnNext.Click
If inc <>(MaxRows -1)Then
inc = inc +1
NavigateRecords()
EndIf
EndSub
PrivateSub btnPrevious_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles btnPrevious.Click
If inc >0Then
inc = inc -1
NavigateRecords()
EndIf
EndSub
PrivateSub btnFirst_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles btnFirst.Click
If inc >0Then
inc =0
NavigateRecords()
EndIf
EndSub
PrivateSub bntLastR_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles bntLastR.Click
If inc <>(MaxRows -1)Then
inc = MaxRows -1
NavigateRecords()
EndIf
EndSub
PrivateSub btnSearch_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles btnSearch.Click
??????
EndSub
End Class
Can someone give a hint of how to proceed?
Thanks,
Darius
Can someone give a hint of how to proceed?
Thanks,
Darius