I am developing an inventory application.
There is a form named frmInventory where material receipt has been done.
Logic
The logic is that First you Enter the Transaction no. in text box named TxtChalanNo
Then a combobox named cmbval on flexgrid named mf1 will got focus then the user select item list from combobox then press enter then he fill qty and amount of the item as per qty the sum of item displayed in next column ie. 5 * 4 = 20. 5 is qty, 4 is amount, and 20 is sum of item displayed in next column. Then when the enter key pressed in amount column sum of item displayed in next column and the new sr. no. of column is generated and then the new row will be added then the user will got focus on a combobox named cmbval on flexgrid named mf1 will got focus then the user select item list from combobox and so on.
The Problem
I came successfully at the first step means the user will fill data successfully in the first row but when the new column is added then the fixed column where i am trying to generate sr no. the user will got the focus i want that the user will got the focus to the combobox named cmbval.
The code is as follows
Public cn As New ADODB.Connection
Dim statement As String
Private Sub cmbVal_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
'>>> find prod rate
Mf1.Text = cmbVal.Text
'>>> show total
If Mf1.Col <> Mf1.Cols - 1 Then
Mf1.Col = Mf1.Col + 1
Else
If Mf1.Row <> Mf1.Rows - 1 Then
Mf1.Row = Mf1.Row + 1
Else
'>>> add new rows
Mf1.Rows = Mf1.Rows + 1
'>>> set the current row
Mf1.Row = Mf1.Row + 1
'>>> set sr no
Mf1.TextMatrix(Mf1.Row, 0) = Val(Mf1.TextMatrix(Mf1.Row - 1, 0)) + 1
End If
Mf1.Col = 1
End If
cmbVal.SelStart = 0
cmbVal.SelLength = Len(cmbVal.Text)
End If
End Sub
Private Sub Form_Load()
Call OpenCon
cmbVal.Visible = True
cmbVal.Text = ""
Mf1.Cols = 5
Mf1.Rows = 2
Call set_heading
Call move_textbox
End Sub
Public Sub OpenCon()
'>>> open connction
If cn.State = 1 Then cn.Close
cn.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source= E:\VB\My Project\eBilling Source Code\data.mdb"
cn.CursorLocation = adUseClient
cn.Open
End Sub
Private Sub Mf1_EnterCell()
If Mf1.Col = 1 Then
'>>> visble combo box for select product
cmbVal.Visible = True
If cmbVal.Visible = True Then
If cmbVal.Enabled = True Then
cmbVal.SetFocus
End If
End If
cmbVal.Clear
Dim Rs As New ADODB.Recordset
If Rs.State = 1 Then Rs.Close
If Mf1.Col = 1 Then
Rs.Open "select prod_sub_type from product_master order by prod_sub_type", cn, adOpenStatic, adLockReadOnly
While Not Rs.EOF
cmbVal.AddItem Rs(0)
Rs.MoveNext
Wend
ElseIf Mf1.Col = 3 Then
cmbVal.AddItem ""
End If
Else
'>>> visble text box for entring quantity
cmbVal.Visible = False
End If
Call move_textbox
End Sub
Private Sub Mf1_KeyPress(KeyAscii As Integer)
Dim i As Long
If KeyAscii = 13 Then 'if Enter Key then...
If Mf1.Cols <> (Mf1.Col + 2) Then 'If current column is not last column...
Mf1.Col = Mf1.Col + 1 'increment col by 1
Else 'If current column is the last column then...
Mf1.Rows = Mf1.Rows + 1 'add a row to the FlexGrid...
Mf1.Col = 0 'set the current column to first column - (0)...
Mf1.Row = Mf1.Row + 1 'set the current row to last row...
Mf1.SetFocus 'set the focus.
End If
Exit Sub
End If
If KeyAscii = 8 Then 'If BackSpace Key then...
If Len(Trim(Mf1.Text)) <> 0 Then 'If current cell is not empty then...
Mf1.Text = Left(Mf1.Text, (Len(Mf1.Text) - 1)) 'Removing a character from the right side of the FlexGrid cell's text
ElseIf Mf1.Rows > 2 Then 'If FlexGrid has more than 2 Rows including the FixedRow then...
For i = 0 To Mf1.Cols - 1 'Checking that the current row is empty or not...
If Len(Trim(Mf1.TextMatrix(Mf1.Row, i))) = 0 Then 'Checking for Empty cell in the current row...
If Mf1.Col <> Mf1.Cols - 1 Then 'Checking that if we reached the last column...
Mf1.Col = Mf1.Col + 1 'goto next column...
Else 'If current columnn is the last column then...
Mf1.Rows = Mf1.Rows - 1 'Remove a Row.
Exit Sub
End If
End If
Next
End If
Else 'If Not BackSpace key then...
Mf1.Text = Mf1.Text + Chr(KeyAscii) 'Append the pressed character to the right.
End If
Exit Sub
End Sub
Private Sub TxtChalanNo_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
cmbVal.SetFocus
End If
End Sub
Private Sub move_textbox()
cmbVal.Left = Mf1.CellLeft + Mf1.Left
cmbVal.Top = Mf1.CellTop + Mf1.Top
cmbVal.Width = Mf1.CellWidth
cmbVal.Text = Mf1.Text
End Sub
Public Sub set_heading()
'>>> creating for the grid
Dim K As Integer
Dim t As Integer
Mf1.Clear
Mf1.Refresh
Mf1.Rows = 3
Mf1.Cols = 5
Mf1.Row = 0
Mf1.RowHeight(0) = 600
Mf1.Col = 0
Mf1.ColWidth(0) = 1000
Mf1.CellForeColor = vbBlue
Mf1.CellFontBold = True
Mf1.CellAlignment = 4
Mf1.Text = "Sr."
Mf1.Col = 1
Mf1.ColWidth(1) = 4200
Mf1.CellForeColor = vbBlue
Mf1.CellFontBold = True
Mf1.CellAlignment = 4
Mf1.Text = "Particulars"
Mf1.Col = 2
Mf1.ColWidth(2) = 1200
Mf1.CellForeColor = vbBlue
Mf1.CellFontBold = True
Mf1.CellAlignment = 4
Mf1.Text = "Quantity"
Mf1.Col = 3
Mf1.ColWidth(3) = 1200
Mf1.CellForeColor = vbBlue
Mf1.CellFontBold = True
Mf1.CellAlignment = 4
Mf1.Text = "Rate"
Mf1.Col = 4
Mf1.ColWidth(4) = 1200
Mf1.CellForeColor = vbBlue
Mf1.CellFontBold = True
Mf1.CellAlignment = 4
Mf1.Text = "Amount"
Mf1.TextMatrix(1, 0) = "1"
Mf1.Row = 0
For K = 0 To Mf1.Cols - 1
Mf1.Col = K
Mf1.CellFontBold = True
Next
Mf1.Row = 1
Mf1.Col = 1
'>>> set serial from 1.2...
For K = 1 To Mf1.Rows - 1
Mf1.TextMatrix(K, 0) = K
Next
Mf1.Row = 1
End Sub
I have also attached the code.
Thanks i am waiting for the reply.