But when I refresh connections.... a lot of data disappear!
What is supposed to happen?
To help us get a better idea of the feel of the Project, speaking as an office manager to a new employee, tell us why, when and how to use the Form.
Please don't speak programmer to programmer, just boss to worker.
lookin over the code in Compiled I see that you are addressing ActiveCell
Private Sub BTN_RECSET_Click()
closeRS
closeRS2
rs.Open strSQL, cnn, adOpenKeyset, adLockOptimistic
Do While Not rs.EOF
ActiveCell.Select
Selection = rs.Fields(0)
ActiveCell.Offset(0, 1).Select
Selection = rs.Fields(1)
rs.MoveNext
Loop
LabVerClear
End Sub
I think you must use a different way if you want to append data to the table
Private Sub BTN_RECSET_Click()
Dim NextRecord As Range
closeRS
closeRS2
rs.Open strSQL, cnn, adOpenKeyset, adLockOptimistic
If Not rs Is Nothing Then
Set NextRecord = Sheets("Foglio1").Cells(Rows.Count. "C").End(xlUp).Offset(1, 0)
Do While Not rs.EOF
NextRecord = rs.Fields(0)
NextRecordOffset(0, 1). = rs.Fields(1)
Set NextRecord = NextRecord.Offset(1, 0)
rs.MoveNext
Loop
Else
MsgBox "The Recordset " & strSQL & " was not opened."
End If
LabVerClear
End Sub
This code has a VBA spelling error
Private Sub BTN_ODBC_Click()
closeRS
closeRS2
sConn = "ODBC;DSN=Excel Files;DBQ=" & matWb & ";"
Set oQt = ActiveSheet.QueryTables.Add(sConn, ActiveCell, strSQL)
With oQt
.FieldNames = False
.HasAutoFormat = False
.AdjustColumnWidth = False
.RefreshOnFileOpen = falso '<------------------ "False"
.BackgroundQuery = False
End With
oQt.Refresh
End Sub
You can avoid such errors by placing "Option Explicit" at the top of code pages. However once you do that, you will have to make many other corrections to the code. Use Debug >> Compile to find all the required corrections without running the Forms.
There are some things I can't help with because I am using Excel 2002 and they are not available to me.