dec2408.doc

i want if user click on save button all the data should store on Mr table But product_name,product_id is not storing properly.
Kindly help me
Private Sub Command1_Click()
' Debug.Assert False
On Error GoTo cancel
Set rs1 = New Recordset
rs1.Open " SELECT * FROM MR ", con, adOpenDynamic, adLockOptimistic
' rs1.Open " SELECT * FROM MR WHERE Grd.Col = '" & Grd.TextMatrix(Grd.Row, cItemCode) & "' ", con, adOpenDynamic, adLockBatchOptimistic
rs1.AddNew
rs1.Fields(1) = Combo1.Text
rs1.Fields(2) = Text1.Text
rs1.Fields(3) = Text2.Text
rs1.Fields(4) = Text3.Text
rs1.Fields(5) = Text4.Text
rs1.Fields(6) = DTPicker2.Value
rs1.Fields(7) = CStr(Text6.Text)
rs1.Fields(8) = Text7.Text
rs1.Fields(9) = DTPicker1.Value
rs1.Fields(10) = Text13.Text
rs1.Fields("qty") = FlexGridEditor.Value
rs1.Fields("Product_name") = Grd.TextMatrix(Grd.Row, cItemName) & vbNullString
rs1!ProductName = Grd.TextMatrix(Grd.Row, cItemName) & vbNullString
rs1.Update
MsgBox ("Commit")
rs1.Close
done:
Exit Sub
cancel:
MsgBox Err.Number
MsgBox Err.Description
Resume done
End Sub

You have two product names, which is which?

I have only one product_name actually citemname is a private const
Option Explicit
Private Const MODULE_NAME = "MR"

Private con As Connection
Private rs As ADODB.Recordset
Private rs1 As ADODB.Recordset
Private X As Integer
Private m_IsOnFixedPart As Boolean
Private m_IsZeroRow As Boolean

Private Const cSlno = 0
Private Const cItemCode = 1
Private Const cItemName = 2
Private Const cUnit = 3
Private Const cQty = 4
Private Const MAX_GRD_COLS = 5
Private GRID_COL_OFFSET As Integer
Private Const CB_SHOWDROPDOWN = &H14F
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Sub Combo1_Click()

From the intial thread you have the following in your code:

rs1.Fields("Product_name") = Grd.TextMatrix(Grd.Row, cItemName) & vbNullString
rs1!ProductName = Grd.TextMatrix(Grd.Row, cItemName) & vbNullString

The 2nd would be the one to get the data. If you step through what does each show in the immediate window

I have also written some code in gridedit()

Private Sub GridEdit(Optional KeyAscii As Integer, Optional EditData As Boolean = False)

On Error GoTo GridEdit_Error
'// Set the control that we'll use to edit
If (KeyAscii = vbKeyReturn Or EditData = True) Then 'Or (KeyAscii >= 65 And KeyAscii <= 91) Or (KeyAscii >= 97 And KeyAscii <= 122) Or (KeyAscii >= 48 And KeyAscii <= 57) Or (KeyAscii = 110) Then
If FlexGridEditor.Visible = True Then
Grd.SetFocus
Else
Select Case Grd.Col
Case cItemCode:
FlexGridEditor.DropDownClass = cnProducts
FlexGridEditor.DropDownDefault = ProductsDefault
'U can use this if you want to filter any records using the 1st character of ITEM_CODE
'FlexGridEditor.ProdFilter = "P"
FlexGridEditor.DropDownIncludeBlank = False
FlexGridEditor.EditControl = emDropDown
FlexGridEditor.Locked = False

Case cItemName:
FlexGridEditor.Locked = False
GoTo GridEdit_Done

Case cUnit:
FlexGridEditor.Locked = False
GoTo GridEdit_Done

Case cQty:
FlexGridEditor.MaxLength = 8
FlexGridEditor.InputType = vldInteger
FlexGridEditor.EditControl = emTextBox
FlexGridEditor.Locked = False

Case Else:
FlexGridEditor.Locked = False
GoTo GridEdit_Done
End Select

'// Set the font of the edit control to be the same as the grid
With FlexGridEditor
'// Get the cell's data
.Value = Grd

'// Position the grid editor control
.Left = Grd.CellLeft + Grd.Left '+ 40
.Top = Grd.CellTop + Grd.Top '+ 40
.Width = Grd.CellWidth * IIf(Grd.Col = cItemCode, 2, 1) '- 40
.Height = Grd.CellHeight '- 40
.Visible = True
.SetFocus
If .EditControl = emDropDown Then SendMessage .hwnd, CB_SHOWDROPDOWN, 1, 0
End With
End If
End If

GridEdit_Done:
Exit Sub

GridEdit_Error:
Call Process_Error(MODULE_NAME, "GridEdit")
Resume GridEdit_Done

End Sub

From the intial thread you have the following in your code:

rs1.Fields("Product_name") = Grd.TextMatrix(Grd.Row, cItemName) & vbNullString
rs1!ProductName = Grd.TextMatrix(Grd.Row, cItemName) & vbNullString

The 2nd would be the one to get the data. If you step through what does each show in the immediate window

After putting entry when i save using save button got
-2147217904 error no when i press CTRL+BREAK without pressing ok button the cursor blinks at MsgBox Err.Description with the
background yellow when i put the cursor upon rs1.Fields("qty") = FlexGridEditor.Value showing flexgrideditor.value="456" whatever
i store but when i put cursor upon rs1.Fields("Product_id"), or rs1.fields("Product_name") getting msg item cannot be found in the
collection

rs1.Fields("Product_name") = Grd.TextMatrix(Grd.Row, cItemName) & vbNullString
rs1!ProductName = Grd.TextMatrix(Grd.Row, cItemName) & vbNullString
in these both line one line is commented

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.