Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

no current record

Status
Not open for further replies.

gc

MIS
Mar 8, 2001
68
0
0
US
Hi!

I create a module to move data from a query to a temp table. one record in the query will be several records in the temp table. I did this before and every thing was fine. but this time i got an error message "No current record". There is one record in the tblTemp after run the procedure. I can't figure out what causes this error, please help and thanks a lot in advance.

George

My code are as following:

Set db = CurrentDb

Set rst = db.OpenRecordset("SELECT * FROM [qryCompTestWrongAnswer]")
rst.MoveFirst

'Open tblTemp which does not have any record

Set rst1 = db.OpenRecordset("tblTemp")

rst1.AddNew
rst1!Question = "1. ....."
rst1!Category = "Clinical"
rst1![#Wrong] = rst.[#Clinical1]
rst1![#TotalTests] = rst.#TotalTests
rst1.Update 'procedure stopped here!!

rst1.AddNew
rst1!Question = "2. ....."
rst1!Category = "Clinical"
rst1![#Wrong] = rst.[#Clinical2]
rst1![#TotalTests] = rst.#TotalTests
rst1.Update

...
rst1.Close
rst.close
 
I would try including WITH recordset as follows:

Set rst = db.OpenRecordset("SELECT * FROM [qryCompTestWrongAnswer]")

WITH rst

Set rst1 = db.OpenRecordset("tblTemp")

WITH rst1

    rst.MoveFirst
  rst1.AddNew
    rst1!Question = "1. ....."
    rst1!Category = "Clinical"
    rst1![#Wrong] = rst.[#Clinical1]
    rst1![#TotalTests] = rst.#TotalTests
    rst1.Update
...

Klasse
 
Just a speculation, but it's possible that your qryCompTestWrongAnswer is a non-updatable query (for whatever reason), and so your .Update call causes an error. Try manually opening the query and adding a record. If it doesn't work, you have your answer. :)

If it does work, then I'll have to speculate some more. ;-)

--Ryan
 
Ryan:
Thank you for your response.
The qryCompTestWrongAnswer has only one record and is non-updatable. So I change that query to a make-table query and create a table. But after run the code I still got same error message.
Please help and thanks again!
George
 
You say you temp table does not have any records when trying to update rst to it, try adding a dummy record to the table and leaving it there.
 
Okay, here's another guess. Maybe when you open your recordset, it's opening read-only by default. Change your OpenRecordset call like this:
Code:
Set rst1 = db.OpenRecordset("tblTemp", dbOpenDynaset)
The dbOpenDynaset parameter will tell Access to let you modify the values in the recordset. Try it, and let me know if it doesn't work.

--Ryan
 
Hi! Ryan and Rich:
Thanks again for your response. I change the recordset call but still got same error.
I debug my code, it runs until update. But the strange thing is that there is one record in the tblTemp. Does this mean the update action is executed? Why I can't get any message after update (Debg.Print " Q1 updated")?
Rich: Because I want update qryCompTestWongAnswer so I delete the records in the tblTemp every time when run the code. And it doesn't matter there is a rcord in the tblTemp or not.
George
 
Alright, let's start at the beginning. So, these are the fields in your tables, right?

qryCompTestWrongAnswer
#TotalTests
#Clinical1
#Clinical2
etc...

tblTemp
Question (Text-type field)
Category (Text-type field)
#Wrong (same type as #Clinical in the query)
#TotalTests (same type as #TotalTests in the query)

Okay, I'm going to redo your code a little bit:
Code:
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim rst1 As DAO.Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("SELECT * FROM [qryCompTestWrongAnswer]")
Set rst1 = db.OpenRecordset("tblTemp", dbOpenDynaset)

With rst1
   .AddNew
      !Question = "1. ....."
      !Category = "Clinical"
      ![#Wrong] = rst![#Clinical1]
      ![#TotalTests] = rst![#TotalTests]
   .Update

   .AddNew
      !Question = "2. ....."
      !Category = "Clinical"
      ![#Wrong] = rst![#Clinical2]
      ![#TotalTests] = rst![#TotalTests]
   .Update

   ...

End With

Set rst1 = Nothing
Set rst = Nothing
set db = Nothing
Just a few subtle changes, but they might make a difference. Or not. I don't know, but this is how I would write it. I guess, try this and see if it works. I'm not sure what else to tell you without actually seeing your database. Good luck! :)

--Ryan
 
Here's another idea. I don't know if this is your problem, but you definitely need to change your field names and get rid of the '#' symbol. (Maybe NumRight, NumWrong instead). Access does not like the '#' symbol in its field names especially as the first character! Maq B-)
<insert witty signature here>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top