Tjenare,Excel VBA: Problem med koppling mellan databasen och excel.
    
    
jag vill att 11A ska skrivas in i en sql-databas. A ändras inte men de kan radnumret göra. Det står att jag måste ha ett uttryck, en konstant eller en variabel när jag ska lägga in de. Problemet är att jag har en variabel.
Detta är koden:
<kod>
Sub WriteToSQL2()
    Dim acrow As String
    acrow = ActiveCell.row
    Dim cella As Date
    cella = Cells(ActiveCell.row, 1).Value
    Dim cellb As Integer
    cellb = Cells(ActiveCell.row, 2).Value
    Dim cellc As Integer
    cellc = Cells(ActiveCell.row, 3).Value
    
    Dim cnt As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim fld As ADODB.Field
    Dim xlCalc As XlCalculation
    Dim wsSheet As Worksheet
    Dim stCon As String, stSQL As String
    Dim i As Long
 
    With Application
        xlCalc = .Calculation
        .Calculation = xlCalculationManual
        .EnableEvents = False
        .ScreenUpdating = False
    End With
 
    Set cnt = New ADODB.Connection
    Set rst = New ADODB.Recordset
 
    stCon = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=SAGEN;Data Source=PATRICB-TP"
 
    stSQL = "INSERT INTO SagProd (Datum, Skift, NomTid)   VALUES (cella, cellb, cellc)"
    Set wsSheet = ActiveSheet
 
    cnt.Open stCon
 
    With rst
        .CursorLocation = adUseClient
        .Open stSQL, cnt, adOpenStatic, adLockReadOnly, adCmdText
        .ActiveConnection = Nothing
    End With
End Sub
</kod>
Tack på förhand!
MVH
Adam Solander