Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving data from MSFlexgrid

Status
Not open for further replies.

deem4

Programmer
Joined
Jun 25, 2003
Messages
4
Location
MU
Hi everybody!
My problem is that I am using an MSFlexgrid on a form in VB 6 and I'm not being able to save the data the user enters in the grid in the database. I have already put a text box on the grid to allow the user to enter data.
I also have a textbox on the form where the clientcode is entered and a command button "save".

Example:
Client Code 01

Job Code Services Fees
01 Consultancy 9000
02 Accounting 10000
03 Maintenance 8000

Result I should get in database:

Clientcode JobCode Services Fees
01 01 Consultancy 9000
01 02 Accounting 10000
01 03 Maintenance 8000

Hope that you will be able to sort out this problem for me. Thanks in advance.




 
Is your grid bound or unbound? How are you filling your grid? Elaborate a bit and post the relevant code.

Thanks and Good Luck!

zemp
 
Hi Zemp,
i'm using an unbound grid. i'm trying to bind it with an ADO control but i'm not being able to do so. The message i'm getting is link to an intrinsic data control. What does that mean? My codes are as follows:

Private Sub MSFlexJob_EnterCell()
If MSFlexJob.MouseRow = 0 Or MSFlexJob.MouseCol = 0 Then
Txt_grid.Visible = False
Exit Sub
End If
Txt_grid.Text = ""
Txt_grid.Visible = False
Txt_grid.Top = MSFlexJob.Top + MSFlexJob.CellTop
Txt_grid.Left = MSFlexJob.Left + MSFlexJob.CellLeft
Txt_grid.Width = MSFlexJob.CellWidth
Txt_grid.Height = MSFlexJob.CellHeight
Txt_grid.Text = MSFlexJob.Text
Txt_grid.Visible = True
Txt_grid.SetFocus
End Sub

Private Sub MSFlexJob_LeaveCell()
MSFlexJob.Text = Txt_grid.Text
End Sub

Private Sub fillflexgrid(ByVal sql As String)
Dim rs As New ADODB.Recordset
Dim count As Integer
Dim MyIndex As Integer
count = 0


rs.Open sql, Cnn, adOpenForwardOnly, adLockReadOnly

Do Until rs.EOF
count = count + 1

MSFlexJob.AddItem vbTab & rs("ClientCode") & vbTab & rs("JobCode")

rs.MoveNext

Loop
MaxRows = count


End Sub

Private Sub search_Click()
Dim strClient As String
Dim ds As New ADODB.Recordset


strClient = InputBox("Enter Client Code")
If strClient = vbNullString Then
Exit Sub
Else
ds.Open "select * from TClient where ClientCode = '" & pstrStatus & "'", Cnn

If ds.EOF = True Then
Call MsgBox("Cannot find record.", vbOKOnly)

Else

Me.ClientCode = ds!ClientCode
Me.ClientName = ds!ClientName
Me.ActivityOfClient = ds!Activity
Me.ContactName = ds!ContactName
Me.DateOfIncorporation = ds!DateOfIncorporation
Me.PartnerName = ds!PartnerName
Me.TDescription = ds!Description
Me.Telephone = ds!Telephone
Me.YearEnded = ds!YearEnded
ds.Close




Dim rs As New ADODB.Recordset
Dim sql
sql = "select * from TClientJob where ClientCode = '" & ClientCode & "' "
rs.Open "select * from TClientJob where ClientCode = '" & ClientCode & "'", Cnn
With MSFlexJob
.TextMatrix(0, 1) = "ClientCode"
.TextMatrix(0, 2) = "Job Code"
.TextMatrix(0, 3) = "Services"
.TextMatrix(0, 4) = "QuotedFees"
.TextMatrix(0, 5) = "Invoice"
End With
fillflexgrid (sql)
End If
End If

End Sub

Private Sub Save_Click()
Dim a
a = ClientCode.Text
CCode.Text = a
Cnn.Execute ("INSERT INTO TClient(ClientCode, ClientName, IncentiveStatus, Description, Activity, DateOfIncorporation, YearEnded, ContactName, PartnerCode, PartnerName, Telephone) VALUES ( '" _
& CCode & "' , '" & ClientName & "' , '" & TIncentiveStatus & "', '" & TDescription & "' , '" & ActivityOfClient & "', '" & DateOfIncorporation & "' , '" & YearEnded & "', '" & ContactName & "', '" & EPartnerCode & "', '" & PartnerName & "', '" & Telephone & "' )")
Cnn.Execute ("INSERT INTO TClientJob(ClientCode) VALUES ('" & ClientCode & "')")

I'm using the above code to insert data in the database but for the flexgrid i dont know how to do it.
Plz help.
Thanks
 
If you are using a floating text box (Txt_Grid) then you will need to use a Txt_Grid key event to place the data into the grid. I usually use the Key_Up event. Here is an example,

Private Sub txtFloat_KeyUp(KeyCode As Integer, Shift As Integer)
'// Assign the value in the text box to the correct grid.
Dim l_intRow As Integer

On Error GoTo ERR_Key

Select Case KeyCode
Case vbKeyRight '// Move one column right.
MSFlexGrid1.Col = MSFlexGrid1.Col + 1 Mod MSFlexGrid1.Cols
Case vbKeyLeft '// Move one column left
MSFlexGrid1.Col = MSFlexGrid1.Col - 1 Mod MSFlexGrid1.Cols
Case vbKeyUp
If MSFlexGrid1.Row > 1 Then
MSFlexGrid1.Row = MSFlexGrid1.Row - 1 Mod MSFlexGrid1.Rows
End If
Case vbKeyDown
If MSFlexGrid1.Row < MSFlexGrid1.Rows - 1 Then
MSFlexGrid1.Row = MSFlexGrid1.Row + 1 Mod MSFlexGrid1.Rows
End If
Case vbKeyReturn, vbKeyBack
'// Do nothing, pressed the enter key, used the backspace key.
Case Else '// Entering values.
MSFlexGrid1.Text = Trim(txtFloat.Text)
End Select
Exit Sub

ERR_Key:
MsgBox Err.Number & &quot;; &quot; & Err.Description
End Sub


Make sure that you update the databse and the grid regularily so that they are copatable.

Also check out faq222-3262.

Thanks and Good Luck!

zemp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top