How am I going to use the command refresh and sort in VB6?

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2008
Posts: 77
Reputation: nagatron is an unknown quantity at this point 
Solved Threads: 0
nagatron nagatron is offline Offline
Junior Poster in Training

How am I going to use the command refresh and sort in VB6?

 
0
  #1
Aug 3rd, 2008
Hello to all, can anyone help me on how to use the "sort" and "refresh" command using MSFlexGrid?
Here is the code:
|-----------------------------------------------------------------------------------------------
Dim WithEvents Con As ADODB.Connection
Dim WithEvents rst As ADODB.Recordset
Dim cmd As ADODB.Command

Private Sub cmdAdd_Click()
chec:

Set rst = New ADODB.Recordset 'specifying attributes to this recordset

With rst

    .ActiveConnection = Con
    .CursorLocation = adUseClient
    .CursorType = adOpenDynamic
    .LockType = adLockOptimistic

.Open "profile2"

End With

'adding records from textbox to recordset

With rst

    .AddNew
    
    .Fields!Name = StrConv(fldName, vbProperCase)
    .Fields!age = StrConv(fldAge, vbProperCase)
    .Fields!sex = StrConv(fldSex, vbProperCase)
    .Fields!tel = StrConv(fldTelNo, vbProperCase)
    .Fields!address = StrConv(fldAddress, vbProperCase)
    .Fields!occupation = StrConv(fldOccupation, vbProperCase)
    .Fields!diagnosis = StrConv(fldDiagnosis, vbProperCase)
    .Fields!treatment = StrConv(fldTreatment, vbProperCase)
    .Fields!remarks = StrConv(fldRemarks, vbProperCase)
    .Fields!Date = StrConv(lblDate2, vbProperCase)
    .Update
    
End With

' clearing the text boxes

fldName = ""
fldAge = ""
fldSex = ""
fldTelNo = ""
fldAddress = ""
fldOccupation = ""
fldDiagnosis = ""
fldTreatment = ""
fldRemarks = ""

' closing the recordset
rst.Close
Set rst = Nothing

Call dload ' calling private procedure to fill the flexgrid

                    'in case of error, informing the user



fldName.Enabled = False
fldAge.Enabled = False
fldSex.Enabled = False
fldTelNo.Enabled = False
fldAddress.Enabled = False
fldOccupation.Enabled = False
fldDiagnosis.Enabled = False
fldTreatment.Enabled = False
fldRemarks.Enabled = False
cmdAdd.Enabled = False

End Sub

Private Sub cmdDelete_Click()

Set cmd = New ADODB.Command ' using command object to execute sql commands

With cmd

    .ActiveConnection = Con
    .CommandType = adCmdText
    .CommandText = "delete from profile2 where name = '" & fldName & "'"
    .Execute

End With

Set cmd = Nothing

' clearing all the text boxes

fldName = ""
fldAge = ""
fldSex = ""
fldTelNo = ""
fldAddress = ""
fldOccupation = ""
fldDiagnosis = ""
fldTreatment = ""
fldRemarks = ""
fldDate = ""

Call dload ' calling procedure to fill flexgrid


End Sub

Private Sub cmdupdate_Click()

On Error GoTo errhan

Set rst = New ADODB.Recordset

With rst

    .CursorLocation = adUseClient
    .ActiveConnection = Con
    .CursorType = adOpenDynamic
    .LockType = adLockPessimistic
    
    .Open "select * from profile2 where name='" & fldName.Text & "'" 'opening the recordset
    
    .Fields!Name = StrConv(fldName, vbProperCase)
    .Fields!age = StrConv(fldAge, vbProperCase)
    .Fields!sex = StrConv(fldSex, vbProperCase)
    .Fields!tel = StrConv(fldTelNo, vbProperCase)
    .Fields!address = StrConv(fldAddress, vbProperCase)
    .Fields!occupation = StrConv(fldOccupation, vbProperCase)
    .Fields!diagnosis = StrConv(fldDiagnosis, vbProperCase)
    .Fields!treatment = StrConv(fldTreatment, vbProperCase)
    .Fields!remarks = StrConv(fldRemarks, vbProperCase)
    .Fields!Date = StrConv(fldDate, vbProperCase)
    
    .Update ' updating the recordset

End With

Set rst = Nothing

Call dload

fldName = ""
fldAge = ""
fldSex = ""
fldTelNo = ""
fldAddress = ""
fldOccupation = ""
fldDiagnosis = ""
fldTreatment = ""
fldRemarks = ""
fldDate = ""

errhan:

If Err.Description <> vbNullString Then
    MsgBox Err.Description
End If

End Sub
Public Sub connect()

Set Con = New ADODB.Connection

Con.CursorLocation = adUseClient

' use this code to connect to the database using universal data link

'Con.Open "File Name=" & App.Path & "\test.udl"

Con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & App.Path & "\db2.mdb"

If Con.Provider = "SQLOLEDB.1" Then
    
    DataEnvironment1.Connections(2).Open Con

Else

    DataEnvironment1.Connections(1).Open Con
    
End If

Call dload

End Sub
Private Sub dload()

MSFlexGrid1.Rows = 1

Set rst = New ADODB.Recordset

    rst.ActiveConnection = Con
    rst.CursorLocation = adUseClient
    rst.CursorType = adOpenDynamic
    rst.LockType = adLockOptimistic
    rst.Source = "profile2"
    rst.Open
    
While Not rst.EOF() ' checking end of file

    MSFlexGrid1.AddItem rst!Name & Chr(9) & rst!age & Chr(9) & rst!sex & Chr(9) & rst!tel & Chr(9) & rst!address & Chr(9) & rst!occupation & Chr(9) & rst!diagnosis & Chr(9) & rst!treatment & Chr(9) & rst!remarks
    
    rst.MoveNext

Wend

Set rst = Nothing

End Sub

Private Sub cmdNew_Click()
fldName = ""
fldAge = ""
fldSex = ""
fldTelNo = ""
fldAddress = ""
fldOccupation = ""
fldDiagnosis = ""
fldTreatment = ""
fldRemarks = ""
fldDate = ""

fldName.Enabled = True
fldAge.Enabled = True
fldSex.Enabled = True
fldTelNo.Enabled = True
fldAddress.Enabled = True
fldOccupation.Enabled = True
fldDiagnosis.Enabled = True
fldTreatment.Enabled = True
fldRemarks.Enabled = True
cmdAdd.Enabled = True

End Sub

Private Sub cmdPrint_Click()

With DataEnvironment1

    If Con.Provider = "SQLOLEDB.1" Then
            
            
            .Commands(2).CommandType = adCmdText
            .Commands(2).CommandText = "SELECT * FROM profile2 where Name = '" & fldName.Text & "'"
            .Commands(2).Execute
            
        DataReport2.Show
            
            
          If .rsCommand2.State = 1 Then
          
            .rsCommand2.Close
          
          End If
        
     
    Else
    
     
            .Commands(1).CommandType = adCmdText
            .Commands(1).CommandText = "SELECT * FROM profile2 where Name = '" & fldName.Text & "'"
            .Commands(1).Execute
        
        DataReport1.Show
        
        If .rsCommand1.State = 1 Then
          
            .rsCommand1.Close
          
        End If
     
    
    End If

End With

End Sub
*****************************************
Private Sub cmdRefresh_Click()

End Sub
*****************************************
Private Sub cmdRefresh_Click()

End Sub
*****************************************
Private Sub cmdSearch_Click()
Form5.Show
End Sub

Private Sub Form_Load()
Call connect
End Sub

Private Sub Form_Unload(Cancel As Integer)

Con.Close
Set Con = Nothing

End Sub

Private Sub mnuExit_Click()
End
End Sub

Private Sub MSFlexGrid1_Click()

With MSFlexGrid1 ' populating the text boxes when user clicks the flexgrid

    .Col = 0
        fldName.Text = .Text
    .Col = 1
        fldAge.Text = .Text
    .Col = 2
        fldSex.Text = .Text
    .Col = 3
        fldTelNo.Text = .Text
    .Col = 4
        fldAddress.Text = .Text
    .Col = 5
        fldOccupation.Text = .Text
    .Col = 6
        fldDiagnosis.Text = .Text
    .Col = 7
        fldTreatment.Text = .Text
    .Col = 8
        fldRemarks.Text = .Text
        
End With

End Sub

Private Sub Timer1_Timer()
lblDate2.Caption = Date
lblTime.Caption = Time
End Sub
|-------------------------------------------------------------------------------------------

this a program than can store data but the problem is i don't know what is the code so i can refresh and sort data inside the MSFlexGrid. . .can anyone help me pls..
see the code, the one that is in red color sub is the problem. . .

email me at: crumple_05@yahoo.com
thank you for the help. . .
Last edited by Tekmaven; Aug 3rd, 2008 at 5:48 am. Reason: Code tags
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 520
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 89
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: How am I going to use the command refresh and sort in VB6?

 
0
  #2
Aug 4th, 2008
The MsFlexGrid.Sort property sorts entire rows. I think it may not useful for particular column.
To Sort
Make the SQL with ORDER BY Clause. This will sort your Records.

To refresh
Also in FlexGrid you are loading the records so you have to Reload everything in Refresh Action.
Selva
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: How am I going to use the command refresh and sort in VB6?

 
0
  #3
Aug 5th, 2008
Hi,

Write this code in Grid's Click event:
  1. If Grd.Row = 1 And Grd.Col > 0 Then
  2. Grd.Sort = 1
  3. End If

Click on any of the Fixed Column (at top) This allows you to Sort the selected Column.

Regards
veena
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 77
Reputation: nagatron is an unknown quantity at this point 
Solved Threads: 0
nagatron nagatron is offline Offline
Junior Poster in Training

Re: How am I going to use the command refresh and sort in VB6?

 
0
  #4
Aug 12th, 2008
Thank you so much. . your code is a big help to me. . .thank you, it works. . =)
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 304
Reputation: aktharshaik is an unknown quantity at this point 
Solved Threads: 37
aktharshaik's Avatar
aktharshaik aktharshaik is offline Offline
Posting Whiz

Re: How am I going to use the command refresh and sort in VB6?

 
0
  #5
Aug 13th, 2008
Another suggestion, use MSHFlexGrid (Heirarchial FlexGrid to populate the records of the recordset. U need not use the loop to populate the records. just use

Open the recordset as KeySet

rst.Open QryString, con, adOpenKeyset
Set MSHFlexGrid1.Recordset = rst
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 41
Reputation: dspnhn is an unknown quantity at this point 
Solved Threads: 4
dspnhn dspnhn is offline Offline
Light Poster

Re: How am I going to use the command refresh and sort in VB6?

 
0
  #6
Aug 21st, 2008
Why don't u use ORDER BY (fieldname) is ur sql query it will definately solve ur sorting and refreshing issue.


Regards
DSP
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum


Views: 1336 | Replies: 5
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC