Link to home
Start Free TrialLog in
Avatar of al4629740
al4629740Flag for United States of America

asked on

record not updating to the table

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

Avatar of NerdsOfTech
NerdsOfTech
Flag of United States of America image

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

Avatar of al4629740

ASKER

I made the change you suggested, but it still does not save the record
ASKER CERTIFIED SOLUTION
Avatar of al4629740
al4629740
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Issue out of the scope of my asked question