Run time error 3061 (1 Viewer)

solnajeff

Registered User.
Local time
Today, 19:00
Joined
May 22, 2007
Messages
33
I have a query which returns a single record based upon using DMax on one field and a lookup value from a form on another.

Run in isolation the query correctly returns a single record but when I try to use the query as a recordset it returns the above error.

The cause of the error is the lookup from the form, if it is replaced by a value then the query can be used without a problem. In all cases the form is open in form view.

The answers I have seen on other websites do not help and I am wondering if anyone has come across this before and could point me in the right direction

Many thanks

Jeff
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 12:00
Joined
May 21, 2018
Messages
8,519
I would get rid of the form reference in the query. Instead build the string

dim rs as dao.recordset
dim formValue as variant
dim strSql as string

formValue = forms("someForm").SomeControl.value
strSql = "Select .... from ... where ... = " & formValue
set rs = currentdb.openrecordset (strSql)
 

solnajeff

Registered User.
Local time
Today, 19:00
Joined
May 22, 2007
Messages
33
Hi

Sorry for the delay.

Many thanks for the suggestions i will try them out and see which works best.

Regards

Jeff
 

solnajeff

Registered User.
Local time
Today, 19:00
Joined
May 22, 2007
Messages
33
Hi

I have used MAJP's suggestion regarding variables and so far so good it is working correctly.

Once again thanks to you both

Regards

Jeff
 

Users who are viewing this thread

Top Bottom