Problem with write DAO

G

Graham

Hi,

Thanks for your help in advance.

I am trying to make the following code write but it keeps
telling me that it is read only.

Please can you tell me where I am going wrong.

Thank you.

Dim dbMyDB As DAO.Database
Dim rsMyRS As DAO.Recordset
Dim lngRecCount As Long
Dim ingInitial As Long
Dim NEWnumber As Long
Dim Number, Chars, MEnd, MonthN, MEnd1
Dim empold As Long
Dim weekold As Date
Set dbMyDB = CurrentDb
Set rsMyRS = dbMyDB.OpenRecordset("Expenses1 Query",
dbOpenDynaset)


NEWnumber = 10000
If rsMyRS.RecordCount <= 0 Then Exit Sub
rsMyRS.MoveLast
lngRecCount = rsMyRS.RecordCount
Text1 = lngRecCount
rsMyRS.MoveFirst

For ingInitial = 1 To lngRecCount
If rsMyRS!exp1emp = empold
Then 'no new employee
If rsMyRS!exp1weekend = weekold
Then 'no new date
Else
NEWnumber = NEWnumber +
1 'new inv no req
rsMyRS.Edit
rsMyRS!expNo = NEWnumber & "E"
rsMyRS.Update
End If

Else
NEWnumber = NEWnumber +
1 'new inv no req
rsMyRS.Edit
rsMyRS!expNo = NEWnumber & "E"
rsMyRS.Update


End If

empold = rsMyRS!exp1emp
weekold = rsMyRS!exp1weekend


Text3 = ingInitial

rsMyRS.MoveNext
Next ingInitial
rsMyRS.Close
dbMyDB.Close
 
B

Brian

Graham said:
Hi,

Thanks for your help in advance.

I am trying to make the following code write but it keeps
telling me that it is read only.

Please can you tell me where I am going wrong.

Thank you.

Dim dbMyDB As DAO.Database
Dim rsMyRS As DAO.Recordset
Dim lngRecCount As Long
Dim ingInitial As Long
Dim NEWnumber As Long
Dim Number, Chars, MEnd, MonthN, MEnd1
Dim empold As Long
Dim weekold As Date
Set dbMyDB = CurrentDb
Set rsMyRS = dbMyDB.OpenRecordset("Expenses1 Query",
dbOpenDynaset)


NEWnumber = 10000
If rsMyRS.RecordCount <= 0 Then Exit Sub
rsMyRS.MoveLast
lngRecCount = rsMyRS.RecordCount
Text1 = lngRecCount
rsMyRS.MoveFirst

For ingInitial = 1 To lngRecCount
If rsMyRS!exp1emp = empold
Then 'no new employee
If rsMyRS!exp1weekend = weekold
Then 'no new date
Else
NEWnumber = NEWnumber +
1 'new inv no req
rsMyRS.Edit
rsMyRS!expNo = NEWnumber & "E"
rsMyRS.Update
End If

Else
NEWnumber = NEWnumber +
1 'new inv no req
rsMyRS.Edit
rsMyRS!expNo = NEWnumber & "E"
rsMyRS.Update


End If

empold = rsMyRS!exp1emp
weekold = rsMyRS!exp1weekend


Text3 = ingInitial

rsMyRS.MoveNext
Next ingInitial
rsMyRS.Close
dbMyDB.Close

Most likely "Expenses1 Query" is not updatable. Updatable queries are
wonderful things, but a query doesn't need to get very complex before the
database engine gives up and can't figure out how to update it. Look up
"updatable" in help for a fairly complete explanation of when queries are or
are not updatable.
 

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