D
David F.
Hello,
I have two different functions created in Access which I'm calling via a
macro to test. One works and the other one complains that the database is
read-only when issuing AddNew. They both update the same file, the only
difference is that one reads from a local table. What's the problem?
This one Works and the table is updated correctly.
************************************************************
Option Compare Database
Public Function AddIP(tablename As String, ip As String, d As Date)
Dim db As Database
Dim rs As Recordset
Dim databasename As String
If ip = "" Then Exit Function
databasename = DLookup("[OrdersIPDSN]", "Settings", "[id]=1")
Set db = OpenDatabase("", dbDriverNoPrompt, False, "ODBC;DSN=" &
databasename)
Set rs = db.OpenRecordset(tablename, dbOpenDynaset)
rs.FindFirst ("IP='" & ip & "'")
If rs.NoMatch Then
rs.AddNew
rs![ip] = ip
rs![ODate] = d
rs.Update
End If
rs.Close
db.Close
End Function
This one does NOT works - AddNew gives read-only halt
************************************************************
Public Function ExportIPData()
Dim db As Database
Dim rsfrom As Recordset
Dim rsto As Recordset
Dim databasename As String
Dim d As Date
databasename = DLookup("[OrdersIPDSN]", "Settings", "[id]=1")
Set db = OpenDatabase("", dbDriverNoPrompt, False, "ODBC;DSN=" &
databasename)
Set rsto = db.OpenRecordset(tablename, dbOpenDynaset)
' tried this - same thing: Set rsto = db.OpenRecordset(tablename,
dbOpenDynaset, 0, dbOptimistic)
Set rsfrom = CurrentDb.OpenRecordset("oinfo", dbOpenDynaset, 0,
dbReadOnly)
While Not rsfrom.EOF
ip = Trim(rsfrom![IPAddress])
d = rsfrom![ODate]
If ip <> "" Then
If IsNull(d) Then
d = #1/1/1980#
End If
rsto.FindFirst ("IP='" & ip & "'")
If rsto.NoMatch Then
rsto.AddNew ' <<<<<<<<<<< Complains that it's read-only (3027)
rsto![ip] = ip
rsto![ODate] = d
rsto.Update
End If
End If
rsfrom.MoveNext
Wend
rsto.Close
rsfrom.Close
db.Close
End Function
I have two different functions created in Access which I'm calling via a
macro to test. One works and the other one complains that the database is
read-only when issuing AddNew. They both update the same file, the only
difference is that one reads from a local table. What's the problem?
This one Works and the table is updated correctly.
************************************************************
Option Compare Database
Public Function AddIP(tablename As String, ip As String, d As Date)
Dim db As Database
Dim rs As Recordset
Dim databasename As String
If ip = "" Then Exit Function
databasename = DLookup("[OrdersIPDSN]", "Settings", "[id]=1")
Set db = OpenDatabase("", dbDriverNoPrompt, False, "ODBC;DSN=" &
databasename)
Set rs = db.OpenRecordset(tablename, dbOpenDynaset)
rs.FindFirst ("IP='" & ip & "'")
If rs.NoMatch Then
rs.AddNew
rs![ip] = ip
rs![ODate] = d
rs.Update
End If
rs.Close
db.Close
End Function
This one does NOT works - AddNew gives read-only halt
************************************************************
Public Function ExportIPData()
Dim db As Database
Dim rsfrom As Recordset
Dim rsto As Recordset
Dim databasename As String
Dim d As Date
databasename = DLookup("[OrdersIPDSN]", "Settings", "[id]=1")
Set db = OpenDatabase("", dbDriverNoPrompt, False, "ODBC;DSN=" &
databasename)
Set rsto = db.OpenRecordset(tablename, dbOpenDynaset)
' tried this - same thing: Set rsto = db.OpenRecordset(tablename,
dbOpenDynaset, 0, dbOptimistic)
Set rsfrom = CurrentDb.OpenRecordset("oinfo", dbOpenDynaset, 0,
dbReadOnly)
While Not rsfrom.EOF
ip = Trim(rsfrom![IPAddress])
d = rsfrom![ODate]
If ip <> "" Then
If IsNull(d) Then
d = #1/1/1980#
End If
rsto.FindFirst ("IP='" & ip & "'")
If rsto.NoMatch Then
rsto.AddNew ' <<<<<<<<<<< Complains that it's read-only (3027)
rsto![ip] = ip
rsto![ODate] = d
rsto.Update
End If
End If
rsfrom.MoveNext
Wend
rsto.Close
rsfrom.Close
db.Close
End Function