Using variables with recordsets

H

halpinj

I am trying to use a variable with the FindFirst method in a recordset. I am
trying to find the first instance of a date and I can find it when I manually
enter the date but whenever I try to put a variable in I get an error
message: "The Microsoft Jet Database does not recognise that as a valid field
name or expression"

i.e. rcdMozart.FindFirst "Date = mydate"

The variable has already been defined previously.

I have also tried pointing it to the actual date field but that also comes
up with the same error message.

i.e. rcdMozart.FindFirst "Date = Forms!Party![Wedding Day]"

I am using Access 2003.
 
A

Arvin Meyer [MVP]

I hope the first one gets deleted as it was sent way before I finished:

Try:

rcdMozart.FindFirst "[Date} =" & Forms!Party![Wedding Day]

You need to concatenate the form reference. Also it is never a good idea to
use a keyword like Date. If you must do so, surround it with brackets.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
H

halpinj

I tried that and it has got rid of the error message, but it doesn't find any
matches even though there is a match there. I've made sure that they are both
in the same format.

Arvin Meyer said:
I hope the first one gets deleted as it was sent way before I finished:

Try:

rcdMozart.FindFirst "[Date} =" & Forms!Party![Wedding Day]

You need to concatenate the form reference. Also it is never a good idea to
use a keyword like Date. If you must do so, surround it with brackets.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access


halpinj said:
I am trying to use a variable with the FindFirst method in a recordset. I am
trying to find the first instance of a date and I can find it when I manually
enter the date but whenever I try to put a variable in I get an error
message: "The Microsoft Jet Database does not recognise that as a valid field
name or expression"

i.e. rcdMozart.FindFirst "Date = mydate"

The variable has already been defined previously.

I have also tried pointing it to the actual date field but that also comes
up with the same error message.

i.e. rcdMozart.FindFirst "Date = Forms!Party![Wedding Day]"

I am using Access 2003.
 
H

halpinj

Has anyone got a solution for this. I have tried the previous advice of
concatenating them and I don't get any error messages but it doesn't find any
matches either. So far I have got:

rcdMozart.FindFirst "[Date] =" & Forms!Party![Wedding Day]


halpinj said:
I tried that and it has got rid of the error message, but it doesn't find any
matches even though there is a match there. I've made sure that they are both
in the same format.

Arvin Meyer said:
I hope the first one gets deleted as it was sent way before I finished:

Try:

rcdMozart.FindFirst "[Date} =" & Forms!Party![Wedding Day]

You need to concatenate the form reference. Also it is never a good idea to
use a keyword like Date. If you must do so, surround it with brackets.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access


halpinj said:
I am trying to use a variable with the FindFirst method in a recordset. I am
trying to find the first instance of a date and I can find it when I manually
enter the date but whenever I try to put a variable in I get an error
message: "The Microsoft Jet Database does not recognise that as a valid field
name or expression"

i.e. rcdMozart.FindFirst "Date = mydate"

The variable has already been defined previously.

I have also tried pointing it to the actual date field but that also comes
up with the same error message.

i.e. rcdMozart.FindFirst "Date = Forms!Party![Wedding Day]"

I am using Access 2003.
 
A

Arvin Meyer [MVP]

There is a possibility that you have used the Now() function as the date,
instead of the Date() function. Now() adds the time and can often lose the
record. For instance if I look for a record for today which has a value of
8/8/2005 3:00 PM and it is 10:00 AM in the morning, I will not find it.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access

halpinj said:
Has anyone got a solution for this. I have tried the previous advice of
concatenating them and I don't get any error messages but it doesn't find any
matches either. So far I have got:

rcdMozart.FindFirst "[Date] =" & Forms!Party![Wedding Day]


halpinj said:
I tried that and it has got rid of the error message, but it doesn't find any
matches even though there is a match there. I've made sure that they are both
in the same format.

Arvin Meyer said:
I hope the first one gets deleted as it was sent way before I finished:

Try:

rcdMozart.FindFirst "[Date} =" & Forms!Party![Wedding Day]

You need to concatenate the form reference. Also it is never a good idea to
use a keyword like Date. If you must do so, surround it with brackets.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access


I am trying to use a variable with the FindFirst method in a recordset. I
am
trying to find the first instance of a date and I can find it when I
manually
enter the date but whenever I try to put a variable in I get an error
message: "The Microsoft Jet Database does not recognise that as a valid
field
name or expression"

i.e. rcdMozart.FindFirst "Date = mydate"

The variable has already been defined previously.

I have also tried pointing it to the actual date field but that also comes
up with the same error message.

i.e. rcdMozart.FindFirst "Date = Forms!Party![Wedding Day]"

I am using Access 2003.
 
H

halpinj

Thanks for all your help. I have now fixed it. Your original suggestion
worked but with extra ' around the concatenated bit.

Arvin Meyer said:
There is a possibility that you have used the Now() function as the date,
instead of the Date() function. Now() adds the time and can often lose the
record. For instance if I look for a record for today which has a value of
8/8/2005 3:00 PM and it is 10:00 AM in the morning, I will not find it.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access

halpinj said:
Has anyone got a solution for this. I have tried the previous advice of
concatenating them and I don't get any error messages but it doesn't find any
matches either. So far I have got:

rcdMozart.FindFirst "[Date] =" & Forms!Party![Wedding Day]


halpinj said:
I tried that and it has got rid of the error message, but it doesn't find any
matches even though there is a match there. I've made sure that they are both
in the same format.

:

I hope the first one gets deleted as it was sent way before I finished:

Try:

rcdMozart.FindFirst "[Date} =" & Forms!Party![Wedding Day]

You need to concatenate the form reference. Also it is never a good idea to
use a keyword like Date. If you must do so, surround it with brackets.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access


I am trying to use a variable with the FindFirst method in a recordset. I
am
trying to find the first instance of a date and I can find it when I
manually
enter the date but whenever I try to put a variable in I get an error
message: "The Microsoft Jet Database does not recognise that as a valid
field
name or expression"

i.e. rcdMozart.FindFirst "Date = mydate"

The variable has already been defined previously.

I have also tried pointing it to the actual date field but that also comes
up with the same error message.

i.e. rcdMozart.FindFirst "Date = Forms!Party![Wedding Day]"

I am using Access 2003.
 
Top