connecting database curopting excel

A

Andre Kruger

Hi

I connect to a access database from excel for data. After this I can not
type in any cell or close excel.

I can close the workbook but have to use taskmanager to end task excel.

What can the problem be?

Please see macro below:

Sub loadtlname()

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim WSOrig As Worksheet
Dim WSTemp As Worksheet
Dim sSQL As String
Dim FinalRow As Long
Set WSOrig = ActiveSheet

'Build a SQL String to get all fields for unsent transfers
un = "'" & Range("s22").Value & "'"
sSQL = "SELECT [name].U, [name].Firstname, [name].Surname "
sSQL = sSQL & " FROM [name] WHERE ((([name].U)=" & un & " ));"

' Path to Transfers.mdb
MyConn = "c:\callstaffmdb.mdb"

Set cnn = New ADODB.Connection
With cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open MyConn
End With
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseServer
rst.Open Source:=sSQL, ActiveConnection:=cnn, _
CursorType:=AdForwardOnly, LockType:=adLockBatchOptimistic, _
Options:=adCmdText

Range("o6").CopyFromRecordset rst

' Close the connection
rst.Close
cnn.Close



Set cnn = Nothing
Set rst = Nothing
Set WSOrig = Nothing
Set WSTemp = Nothing


Set WSOrig = Nothing
Application.DisplayAlerts = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top