My code to retrieve value is as below:
Sub UploadData()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
Dim strConn As String
Dim sql As String
strConn = "PROVIDER=SQLOLEDB;DATA SOURCE=.\sql2000;INITIAL CATALOG=EquityDB;INTEGRATED SECURITY=sspi;"
cn.Open strConn
sql = "select * from EquityDB.dbo.table1 where field1 = '" & Replace(Range("d1").Value, "'", "''") & "'"
rs.Open sql, cn, adOpenDynamic, adLockOptimistic
GetData = rs.Fields(0).Value
If Not GetData = "" Then
cn.Execute sql001
Else
cn.Execute sql002
End If
sql001 is an insert, and sql002 is an update
When I run the macro, I got error saying operation is not allowed when the record is open for the line
rs.Open sql, cn, adOpenDynamic, adLockOptimistic
If I change
If Not GetData = "" Then
to
If Not GetData Is Null Then
I get error saying "object required" with the line
If Not GetData Is Null Then
Any advice on how to fix the bug would be great!
If Not IsEmpty(GetData) then