2 Replies - 640 Views - Last Post: 14 February 2013 - 04:22 PM Rate Topic: -----

#1 jcgonz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 02-February 10

Synchronizing textboxes with selected item on datagrid! Problem.

Posted 13 February 2013 - 01:07 AM

Hallo!

I need help once more with my sample program. Can't ask a teacher or professor since I am self-studying.

Posted Image

I can't seem to make the textboxes on the right display additional details from my database which isn't shown on the dataGrid.

Here's my code for the current form:
Option Explicit
'variable declaration
Dim RS As ADODB.Recordset
Dim strSQL As String
'end of declarations

Private Sub cmdReload_Click()
strSQL = "Select StuNo, LastName, FirstName, MI, Course, Year, Section from tblCS;"
Call OpenNewRecordset
Call LoadDataOnGrid

End Sub

Private Sub cmdAlphabetical_Click()
strSQL = "Select StuNo, LastName, FirstName, MI, Course, Year, Section from tblCS order by LastName, FirstName;"
Call OpenNewRecordset
Call LoadDataOnGrid

End Sub

Private Sub cmdYearSection_Click()
strSQL = "Select StuNo, LastName, FirstName, MI, Course, Year, Section from tblCS order by Year, Section, LastName;"
Call OpenNewRecordset
Call LoadDataOnGrid
End Sub

Private Sub cmdStuNo_Click()
strSQL = "Select StuNo, LastName, FirstName, MI, Course, Year, Section from tblCS order by StuNo;"
Call OpenNewRecordset
Call LoadDataOnGrid

End Sub

Private Sub Form_Load()
CenterForm Me 'keep form in center
Connectonload 'connect dbCS on form load
Call cmdReload_Click 'load all data to grid
End Sub

Private Sub OpenNewRecordset() 'for fast opening of recordset
Set RS = New ADODB.Recordset
RS.CursorLocation = adUseClient
RS.Open strSQL, gCONN, adOpenKeyset, adLockOptimistic, adCmdText

'display current query on txtCurrQuery
txtCurrQuery.Text = strSQL
End Sub

Private Sub LoadDataOnGrid()
'setup datagrid data
Set datGridMain.DataSource = RS
Exit Sub
End Sub



and here are the codes for the module used by the form:
Option Explicit
'declare connection variables
Public gCONN As ADODB.Connection
Public gRS As ADODB.Recordset
Public gStrSQL As String
'end of declarations

Public Sub Connectonload()
'reload connection variables
Set gCONN = New ADODB.Connection

'set gCONN properties
gCONN.ConnectionString = "Driver={MySQL ODBC 3.51 Driver};" _
& "Server=127.0.0.1;" _
& "Database=dbCS;" _
& "User=root;" _
& "Password=root;" _
& "Option=3"

'open connection to database
gCONN.Open
End Sub

Public Sub CenterForm(objForm As Form)
'Center Form
With objForm
    .Top = (Screen.Height - .Height) / 2
    .Left = (Screen.Width - .Width) / 2
End With
End Sub



I've tried adding a data control and using the settings equal to the module's but I still can't make it work.

Please help me. Any suggestions or advice would be good. I just need hints, but a little spoonfeeding would be nice. :D/>/>

This post has been edited by jcgonz: 13 February 2013 - 01:12 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Synchronizing textboxes with selected item on datagrid! Problem.

#2 TheKirk  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 58
  • Joined: 10-February 13

Re: Synchronizing textboxes with selected item on datagrid! Problem.

Posted 13 February 2013 - 02:08 AM

First of al, I would suggest you dump Visual Basic 6, or Visual basic at all. It's a horrible and unproductive language in my opinion. Either start using Visual Basic with .NET Framework 4.0 or switch to C# with .NET Framework 4.0.

To get all data associated with a row in your database you should make a query to retreive all columns:

strSQL = "Select * from tblCS order by Year, Section, LastName;"

Was This Post Helpful? 0
  • +
  • -

#3 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Synchronizing textboxes with selected item on datagrid! Problem.

Posted 14 February 2013 - 04:22 PM

Horrible and unproductive? That's a little strong. Obsolete maybe. Productive certainly not; I've made a whole lot of money using it, and some of my apps are still in use after 15 years.

Jc, does your datagrid have to display all of the fields/columns in your recordset, or can you avoid displaying some of them?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1