Solved

Append Query in VBA runtime error 3061

Posted on 2008-10-03
5
258 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
  • 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

791 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