ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Ado / Adox ? (https://www.excelbanter.com/excel-programming/315992-ado-adox.html)

silvest[_19_]

Ado / Adox ?
 

I still don't really get it :(

Set conn = New ADODB.Connection
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source="
& Worksheet.mdb
sqlstring = "DELETE FROM Table1 where salary 0"
conn.Execute sqlstring
conn.Close

Set conn = New ADODB.Connection
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" &
Worksheet.mdb

Dim Recordset1 As ADODB.Recordset
Set Recordset1 = New ADODB.Recordset

Recordset1.Open "SELECT * FROM Table1",
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Worksheet.mdb, adOpenStatic, adLockOptimistic


After that line of codes, there's this:
Recordset1.AddNew
Recordset1("Date") = FormatDateTime(DateTime)
Recordset1("Salary") = Salary

Now this is part of a loop that takes the salary at each date.

At the end of the loop, only i put:
Recordset1.Update
Recordset1.Close
Set Recordset1 = Nothing



TK Wrote:
Hi silvest:

Re read your code.

sqlstring = "DELETE FROM Table1"
conn.Execute sqlstring


You have deleted all records in Table1

Recordset1.Open "SELECT * FROM Table1",


nothing left in Table1 to select

BOF or EOF is TRUE, or the current record has been deleted.


so the error statement is correct.

A couple of reminders:
use DELETE with a WHERE to remove selected records
use the INSERT statement to add records
use UPDATE to change existing records

Also in your statement Recordset1.Update if you were updating a record
it would have to be something like

Update Table1
Set Field_whatever =' new value'
where field_whatever = ' condition '

Good Luck
TK


"silvest" wrote:


Set conn = New ADODB.Connection
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source="
& Worksheet.mdb
sqlstring = "DELETE FROM Table1"
conn.Execute sqlstring
conn.Close

Set conn = New ADODB.Connection
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" &
Worksheet.mdb

Dim Recordset1 As ADODB.Recordset
Set Recordset1 = New ADODB.Recordset

Recordset1.Open "SELECT * FROM Table1",
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Worksheet.mdb, adOpenStatic, adLockOptimistic




Myrna Larson Wrote:
Can you post the rest of your code, specifically the line(s) tha

open
the
recordset?

On Fri, 5 Nov 2004 13:41:14 -0600, silvest
wrote:


Hi, i'm not too familiar with VBA in Excel, but i'll try my best.

I'm trying to run a macro that'll generate numbers and fit i

into
Access DB (which i've created using another macro)

the loop seems to be running fine, but an error occurs saying:
"Either
BOF or EOF is TRUE, or the current record has been deleted

Requested
operation requires a current record."
and points towards this line: "

-- Recordset1.Update <--
Recordset1.Close
Set Recordset1 = Nothing



--
silvest


------------------------------------------------------------------------
silvest's Profile

http://www.excelforum.com/member.php...o&userid=14662
View this thread

http://www.excelforum.com/showthread...hreadid=275742



--
silves
-----------------------------------------------------------------------
silvest's Profile: http://www.excelforum.com/member.php...fo&userid=1466
View this thread: http://www.excelforum.com/showthread.php?threadid=27574



All times are GMT +1. The time now is 06:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com