record not updating to the table

al4629740
al4629740 used Ask the Experts™
on
I am having issues with this code in VB6.  When i click the command button, the new record will show up in the datagrid but then it wont update to the table.  Do you see anything missing or wrong?

Private Sub Command7_Click()

Set conn = New ADODB.Connection
Set rec = New ADODB.Recordset

        If conn.State = adStateClosed Then
        conn.Open "Provider=sqloledb;Data Source=" & ConnectionIP & ",xxxxx;Network Library=DBMSSOCN;Initial Catalog= " & CAPDB & "; User ID=xxxx;Password=xxxxx"
        End If



esql = "select LinkageName, Linkage, AgreementDate from tblOrgMonthlyLinkages where Fiscal = " & Fiscal & " order by AgreementDate"


If rec.State = adStateOpen Then
        rec.Close
End If


      rec.CursorType = adOpenStatic
      rec.CursorLocation = adUseClient
      rec.LockType = adLockOptimistic
      rec.Open esql, conn, , , adCmdText


        rec.AddNew
        rec!LinkageName = Text3
        rec!Linkage = Text5
        rec!AgreementDate = DTPicker4
        rec.Update
      
        Set DataGrid1.DataSource = rec

    
    If rec.RecordCount > 0 Then
    rec.MoveFirst
    End If
            
        DataGrid1.Columns(0).Width = 2500
        DataGrid1.Columns(1).Width = 4500
        DataGrid1.Columns(2).Width = 1500
        


End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
NerdsOfTechTechnology Scientist

Commented:
It looks like you are closing the recordset before opening it, move this to around line 42

If rec.State = adStateOpen Then
        rec.Close
End If

Open in new window

Author

Commented:
I made the change you suggested, but it still does not save the record
Looks like my issue was related to something outside the scope of my original question.  Thanks as I have it solved.

Author

Commented:
Issue out of the scope of my asked question

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial