VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



By using Microsoft FlexGrid Control 6.0 we can enter Mualtiple records at the form.Microsoft FlexGr

by shahid (2 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 31st March 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

By using Microsoft FlexGrid Control 6.0 we can enter Mualtiple records at the form.Microsoft FlexGrid Control 6.0 is for searching,updating.

Rate By using Microsoft FlexGrid Control 6.0 we can enter Mualtiple records at the form.Microsoft FlexGr




Dim rstemp As New ADODB.Recordset
Dim rsitems As New ADODB.Recordset
Dim rsgrn As New ADODB.Recordset
Dim rsgrndesc As New ADODB.Recordset
Dim rsreport1 As New ADODB.Recordset
Dim rsreport2 As New ADODB.Recordset


Private Sub cmbinput_KeyPress(KeyAscii As Integer)
 
 If KeyAscii = 13 Then
 
 End If
  
End Sub



Private Sub cmbcode_Change()
 If cmbcode.Text <> "" Then
    rstemp.Open "select * from product where pcode= '" & cmbcode.Text & "'", cn, adOpenStatic, adLockOptimistic
    txtname.Text = rstemp.Fields("pname").Value
    rstemp.Close
    txtqty.SetFocus
 End If
End Sub


Private Sub cmdadd_Click()
 If txtprice.Text <> "" And txtqty.Text <> "" And cmbcode.Text <> "" Then
  If IsNumeric(txtprice.Text) And IsNumeric(txtqty.Text) Then
      
      ' add to the grid
      Dim row As Integer
      row = Grid1.Rows - 1
      
      Grid1.TextMatrix(row, 0) = row
      Grid1.TextMatrix(row, 1) = cmbcode.Text
      Grid1.TextMatrix(row, 2) = txtname.Text
      Grid1.TextMatrix(row, 3) = "Ltr"
      Grid1.TextMatrix(row, 4) = txtqty.Text
      Grid1.TextMatrix(row, 5) = txtprice.Text
      Grid1.TextMatrix(row, 6) = Format((Val(txtqty.Text) * Val(txtprice.Text)), ".00")
      
      Grid1.Rows = Grid1.Rows + 1
      cmbcode.Text = ""
      txtname.Text = ""
      txtqty.Text = ""
      txtprice.Text = ""
      cmbcode.SetFocus
     
  Else
     MsgBox "Invalid data", vbCritical
  End If
 Else
  MsgBox "No data in the fields", vbCritical
 End If
End Sub

Private Sub cmdcancel_Click()
  Unload Me
End Sub


Private Sub cmdsave_Click()
  
  Dim i As Integer
  
  ' whole grid is empty
  If Grid1.Rows < 3 Then
    MsgBox "There is no record to save"
    Exit Sub
  End If
  
  On Error GoTo databaseerror
  
  ' start saving
  rsgrn.Open "grn", cn, adOpenDynamic, adLockOptimistic
  rsgrndesc.Open "grndesc", cn, adOpenDynamic, adLockOptimistic
  rsitems.Open "product", cn, adOpenDynamic, adLockOptimistic
  
  
  ' start transaction
  cn.BeginTrans
  
  rsgrn.AddNew
  rsgrn.Fields("grnno") = txtgrn.Text
  rsgrn.Fields("grndate") = txtdate.Text
  rsgrn.Update
  
  For i = 1 To Grid1.Rows - 2
      rsgrndesc.AddNew
      rsgrndesc.Fields("grnno") = txtgrn.Text
      rsgrndesc.Fields("pcode") = Grid1.TextMatrix(i, 1)
      rsgrndesc.Fields("value") = Val(Grid1.TextMatrix(i, 6))
      rsgrndesc.Fields("quantity") = Val(Grid1.TextMatrix(i, 4))
      rsgrndesc.Update
      
      rsitems.MoveFirst
      rsitems.Find "pcode = '" & Grid1.TextMatrix(i, 1) & "'"
      If Not rsitems.EOF Then
        rsitems.Fields("tquantity") = rsitems.Fields("tquantity") + Val(Grid1.TextMatrix(i, 4))
        rsitems.Fields("tvalue") = rsitems.Fields("tvalue") + Val(Grid1.TextMatrix(i, 6))
        rsitems.Update
      Else
        GoTo databaseerror
      End If
  Next i
  
  
  ' commit transaction to save changes
  cn.CommitTrans
   
   
  MsgBox "The data has been saved successfully", vbInformation, "FMC United"

  rsgrn.Close
  rsgrndesc.Close
  rsitems.Close
  
  Grid1.Clear
  Call initgrid
  txtgrn.Text = Val(txtgrn.Text) + 1
  cmbcode.SetFocus
  
  Exit Sub
  
databaseerror:
  cn.RollbackTrans
  rsgrn.Close
  rsgrndesc.Close
  rsitems.Close
  MsgBox "The following error has occured while saving data :      " & Chr(13) + Chr(10) & "    No : " & Err.Number & "  Description : " & Err.Description
End Sub

Private Sub Form_Load()

   Call initgrid
   
   Set rs = New ADODB.Recordset
   rs.Open "select count(grnno) + 1 from grn", cn, adOpenDynamic, adLockOptimistic
   txtgrn.Text = rs.Fields(0).Value
   rs.Close
   Set rs = Nothing
   
   txtdate.Text = Date
     
   Grid1.Col = 0
   Grid1.row = 0
   
   
 'form sizing
    Me.Height = 6850
    Me.Width = 9270
    
    cmbcode.Visible = True
   
End Sub

Private Sub Form_Unload(Cancel As Integer)
  ' Set cn = Nothing
End Sub


Public Sub initgrid()
   
   Dim s As String

   s$ = "<SR_NO|Product ID|Description|Unit|Quantity|Price|Net Price"
   Grid1.FormatString = s$
   Grid1.ColWidth(1) = 1200
   Grid1.ColWidth(2) = 2575
   Grid1.ColWidth(3) = 800
   Grid1.ColWidth(4) = 1000
   Grid1.ColWidth(5) = 1000
   Grid1.ColWidth(6) = 1370
   
   Grid1.ColAlignment(4) = 7
   Grid1.ColAlignment(5) = 7
   Grid1.ColAlignment(6) = 7
   
   Grid1.Rows = 2
   
End Sub



Download this snippet    Add to My Saved Code

By using Microsoft FlexGrid Control 6.0 we can enter Mualtiple records at the form.Microsoft FlexGr Comments

No comments have been posted about By using Microsoft FlexGrid Control 6.0 we can enter Mualtiple records at the form.Microsoft FlexGr. Why not be the first to post a comment about By using Microsoft FlexGrid Control 6.0 we can enter Mualtiple records at the form.Microsoft FlexGr.

Post your comment

Subject:
Message:
0/1000 characters