473,473 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Run-time Error 3061 - Recordset

5 New Member
Got myself in real need of help here, and wonder whether anyone would be able to assist?

Problem:-
In a wildlife hospital we want to automatically select the ‘Previous Accession Number’ under which an animal known by its ‘First Accession Number’ (or ‘PatientID’) was last treated by CWH before the current consultation instance.

Each instance of an animal entering the wildlife hospital is automatically given an auto-numbered AccessionID (or ‘Consultation number’). If it survives and is discharged into the care of a Carer (with a ‘Discharge Advice’), the Carer may later need to bring it back to the hospital any time (and maybe multiple times) for the vet to re-check its progress. When this happens the Carer is asked for its ‘First Accession Number’ (or ‘PatientID’) from the previous ‘Discharge Advice’ so that we can accurately identify the animal and gain access to its latest veterinary notes, etc.. The AnimalGroup of the animal is selected as ‘ReCheck’ which then directs the flow of the re-admission process, which now has already been given a new AccessionID (or ‘Consultation number’) to the Re-Check Admission screen (‘FRM_AdmnReCheck’).

We assume (from experience) that the Carer will not always be able to quote its previous AccessionID (or ‘Consultation number’), but will know (or be able to be prompted to) its ‘First Accession Number’ (or ‘PatientID’).
We want to enter its ‘First Accession Number’ (or ‘PatientID’) in field ‘FirstAccNo’, and having done so, for the program to automatically look up the accession number when it was last admitted.

The program uses linked CWHDB (in the central server) and CWHClient (on the user machines) files.

My Solution So Far:-
Use a recordset of a query pre-defined in the CWHClient file to list all the consultation numbers (AccessionIDs) where the ‘FirstAccNo’ of the animal is the number entered into the ‘FirstAccNo’ field of the Re-Check Admission screen, and then to use the MoveLast, FindPrevious method to identify the previous accession number . This query is ‘QRY_PrevAccNo’ (“
Expand|Select|Wrap|Line Numbers
  1. SELECT TBL_Accession.AccessionID, TBL_Accession.FirstAccNo FROM TBL_Accession WHERE (((TBL_Accession.FirstAccNo)=[Forms]![FRM_AdmnReCheck].[FirstAccNo].[Value])) ORDER BY TBL_Accession.AccessionID;”
). The vba I have is:-

Expand|Select|Wrap|Line Numbers
  1. Private Sub FirstAccNo_AfterUpdate()
  2. 1    Dim dbs As DAO.Database
  3. 2    Dim rst As DAO.Recordset
  4. 3    Dim pan As Long
  5.  
  6. 4    Set dbs = CurrentDb
  7. 5    Set rst = dbs.OpenRecordset("QRY_PrevAccNo", dbOpenDynaset)
  8. 6    With rst
  9. 7        If Not (.BOF And .EOF) Then
  10. 8            .MoveLast
  11. 9            .FindPrevious ("AccessionID")
  12. 10            If Not .NoMatch Then
  13. 11                pan = rst!AccessionID.Value
  14. 12           Else
  15. 13                GoTo ExitSub
  16. 14            End If
  17. 15        Else
  18. 16            MsgBox ("No records!")
  19. 17        End If
  20. 18    End With
  21. 19    Forms!FRM_AdmnReCheck.PrevAccNo.Value = pan
  22. 20    Set dbs = Nothing
  23. 21    Set rst = Nothing
  24. ExitSub:
  25. End Sub
However, this trips out at Run-time on line 5, with Run-time error 3061 (“Too few parameters. Expected: 1”)

A typical result of running the query for value 21715 in field Forms!FRM_AdmnReCheck.FirstAccNo is:-
QRY_PrevAccNo
AccessionID FirstAccNo
21715 21715
21765 21715
21864 21715
21926 21715
22016 21715
22340 21715
22358 21715
22359 21715
Where 22358 would be the result value needed.

I have spent many hours researching, but so far have failed to find a solution. Can’t think of any other way around this! Any ideas would be very welcome indeed!
May 16 '13 #1
8 1658
Rabbit
12,516 Recognized Expert Moderator MVP
Please use code tags when posting code.

You really should have another table to track unique animals instead of having to look for the first instance the animal came into the hospital. It would normalize your data and make everything a lot easier to maintain.

As far as what you're trying to do, you can use a max aggregate query to get what you're looking for. No need for any code.
May 16 '13 #2
Megagnome
5 New Member
Thanks VERY much, 'Rabbit'! What would my 'max aggregate query look like? Could you give me a clue as to the SQL? That's a term that is new to me!
May 16 '13 #3
Megagnome
5 New Member
Rabbit, the problem that I see with what I think you suggest is that that would give me the highest (max) AccessionID. I don't want that value. It's the PREVIOUS value we want, that is, 22358, NOT 22359 which would be the max, and yes, I agree that if I wanted the max I'd have no need for the code.
May 16 '13 #4
Rabbit
12,516 Recognized Expert Moderator MVP
Just have it ignore the most recent one.

Expand|Select|Wrap|Line Numbers
  1. select max(fieldName)
  2. from tableName
  3. where fieldName <> currentValue
  4.    and groupField = groupVale
May 17 '13 #5
Megagnome
5 New Member
So,
Expand|Select|Wrap|Line Numbers
  1. SELECT max(AccessionID) FROM TBL_Accession
  2. WHERE AccessionID <> Me.AccessionID
  3. AND FirstAccNo = Me.FirstAccNo
  4.  
then place this as Record Source for field PrevAccNo? Certainly much simpler, but please confirm!
May 17 '13 #6
Rabbit
12,516 Recognized Expert Moderator MVP
You'll probably need to populate it through code. But the code would only be one line as opposed to what you had before.
May 17 '13 #7
Megagnome
5 New Member
Thank you, thank you kind Rabbit! MUCH better. By sorting DESC and restricting the ListRows to 1 our receptionists now have no choice other than the correct number. Most grateful!
May 18 '13 #8
Rabbit
12,516 Recognized Expert Moderator MVP
Not a problem, good luck with the rest of your project.
May 18 '13 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Miranda Evans | last post by:
I noticed several postings about issues related to "run-time error 3061", and I observed that the solutions to these issues appear to involve correcting something within the SQL code. I'm...
3
by: colm | last post by:
i get the above runtime error on the following line of code when i try to update a reord in my form when it gets to the line Set rs = DBEngine(0)(0).OpenRecordset(strSql) the entire code...
2
by: Steve Richfield | last post by:
There have been LOTS of postings about error 3061, but mine seems to be an even simpler case than the others. I have a simple **FUNCTIONING** query called qryEdits. Copying the SQL from the query,...
2
by: fanfromfla | last post by:
I am using a database that has worked for many years for a holiday project for needy families. My organization recently upgraded its server and changed everyone to Windows XP. I just mention that...
4
by: Richard Hollenbeck | last post by:
I thought I was very specific in this SQL request. There is a form open with a selected record (and a corresponding "lngRecipeID" on that form. The table also has a field called "lngRecipeID". ...
4
by: JH001A | last post by:
ACCESS 2003 VBA in the code below set.rs3, gets the error when I try using a parm for input to the where clause. If I use a number like the one comented out it works. Thanks for your help. ...
1
by: Richard Hollenbeck | last post by:
I wonder what I'm missing? I really feel like a retard because I've been screwing with some code for a very long time. I just must be missing something very simple. In the following example,...
1
by: istya | last post by:
I am having a dumb day to day. Can anyone have a schufty at my code and see why I am getting the runtime error 3061? I'm working on 2000 if that helps at all. Dim dbs As DAO.Database Dim...
3
by: phill86 | last post by:
Hi, I am trying to run the following query in a recordset and i get the following error message Runtime error 3061 - Too few parameters. Expected 1 i am using the following code
4
by: shalskedar | last post by:
In my DB(Ms Access 2003)I want to delete a record from 1 table which is linked to another table. For ex- There are 2 tables "MasterType" which is the Master table & another table as "Sash DO"...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.