Hello everyone,
I was just trying to save data from a FlexGrid to a MS Access database (learned form VBForum), it's a basic one for learning purpose.
The database contains only one table with following 04 columns -
num, docName, docAddr & phNo.

here is the code -

Code:
Private Type doctor
 dName As String
 dNo As Integer
 dAddress As String
 pNo As Integer
End Type
Dim d(10) As doctor
Dim i, j, response As Integer

Public con As ADODB.Connection
Public rs As ADODB.Recordset


Private Sub cmdDB_Click()

Dim iRows As Integer
Dim iCols As Integer


Set con = New ADODB.Connection
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data.mdb;Persist Security Info=False"
con.CursorLocation = adUseClient
Set rs = New ADODB.Recordset

rs.Open "select * from doc", con, adOpenDynamic, adLockPessimistic, adCmdText


While rs.EOF = True

With fg
For i = 0 To fg.Rows - 1
rs.AddNew
rs.Fields(num) = fg.TextMatrix(i + 1, 0)
rs.Fields(docName) = fg.TextMatrix(i + 1, 1)
rs.Fields(docAddr) = fg.TextMatrix(i + 1, 2)
rs.Fields(phNo) = fg.TextMatrix(i + 1, 3)
rs.Update
'rs.MoveNext
Next i

End With
Wend




End Sub

Private Sub cmdDisplay_Click()
fg.Rows = fg.Rows + 1
For j = 1 To i
fg.Row = j
fg.Col = 0
fg.Text = d(j - 1).dNo
fg.Col = 1
fg.Text = d(j - 1).dName
fg.Col = 2
fg.Text = d(j - 1).dAddress
fg.Col = 3
fg.Text = d(j - 1).pNo
Next j

response = MsgBox("Want to enter more data?", 1, App.Title)

If (response = 1) Then
  cmdDisplay.Enabled = False
  cmdInput.Enabled = True
  
Else
  cmdDisplay.Enabled = False
  cmdDB.Enabled = True
End If

End Sub

Private Sub cmdInput_Click()
d(i).dNo = InputBox("doctor's no")
d(i).dName = InputBox("doctor's Name")
d(i).dAddress = InputBox("doctor's Address")
d(i).pNo = InputBox("doctor's Contact no")
i = i + 1

cmdInput.Enabled = False
cmdDisplay.Enabled = True


End Sub

Private Sub Form_Load()
fg.Cols = 4
fg.Row = 0
fg.Col = 0
fg.Text = "Doctor's N0."

fg.Col = 1
fg.Text = "Doctor's Name"

fg.Col = 2
fg.Text = "Doctor's Address"

fg.Col = 3
fg.Text = "Contact No."

fg.ColWidth(0) = 1000
fg.ColWidth(1) = 1200
fg.ColWidth(2) = 1500
fg.ColWidth(3) = 1200


cmdDisplay.Enabled = False
cmdDB.Enabled = False



End Sub
I'm getting error - "Run-Time error '3265' Item cannot be found in the collection corresponding
to the requested name or ordinal"

Tried a lot but can't find the error.
Please help.
A lot of thanks in advance

Name:  flex.jpg
Views: 600
Size:  49.2 KB