Solved

Append Query in VBA runtime error 3061

Posted on 2008-10-03
5
260 Views
Last Modified: 2013-11-27
Hi Everyone,

I don't know why this won't work:

Dim rs As Recordset

Set rs = CurrentDb.OpenRecordset("SELECT * FROM subPatientGoal WHERE patientID = " & Me.Text49 & " and goaldesc = " & Me.listGoals)

If rs.EOF Then
      DoCmd.OpenQuery "AppendGoals"
    Me.ListFinalGoal.Requery
Else
   MsgBox "This has already been added as a goal."
End If

rs.Close
Set rs = Nothing

Can anyone help me?  It's urgent!

Thanks
Jetera
0
Comment
Question by:jetera
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 22634584
Hello jetera,

What is the point of opening the recordset?  You're not actually doing anything with it.

Try declaring rs as DAO.Recordset, and changing the open line to:

Set rs = CurrentDb.OpenRecordset("SELECT * FROM subPatientGoal WHERE patientID = '" & Me.Text49 & "' and goaldesc = "' & Me.listGoals & "'")

Regards,

Patrick
0
 

Author Comment

by:jetera
ID: 22634655
I was using it as a check to see if there is already a record in the table.  

I used your syntax and that part works...thanks :)

Now the rs.eof is not recognizing that their are records...
I thought rs.eof=true meant that no records were returned?  Basically I am checking the table for two values before appending the record.  When I know there are records with those values, it is supposed to go to the "else" statement but it is not doing that.
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 22634883
jetera said:
>>I was using it as a check to see if there is already a record in the table.  

OK, I missed that :)

>>Now the rs.eof is not recognizing that their are records...

Before testing the EOF, try:

rs.MoveLast
rs.MoveFirst
0
 

Author Closing Comment

by:jetera
ID: 31502779
Thanks!
0
 

Author Comment

by:jetera
ID: 22635048
Thanks!!!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question