Open Form Command gives Runtime error

  • Thread starter Thread starter Tim B.
  • Start date Start date
T

Tim B.

Some one please help, I have been stuck on this for two
days now. I am trying to open a form with a
docmd.openform command. The form opens but will not open
to the correct record. The problem seems to be in the
find part of the criteria when calling the date. Here is
the code:
DoCmd.OpenForm "frm_letter_of_indemnity",
acNormal, , "policy_number = '" & strpolicynumber & "' and
start_date = '" & strstartdate & "'"

When the start_date is text field in the table then
everything seems to work fine. But when the start_date is
a date field in the table I get the "OpenForm Action was
Cancelled" error. I need to have the start date as a date
field for other date caculations in the program.

All help appreciated-Tim B
 
Tim B. said:
Some one please help, I have been stuck on this for two
days now. I am trying to open a form with a
docmd.openform command. The form opens but will not open
to the correct record. The problem seems to be in the
find part of the criteria when calling the date. Here is
the code:
DoCmd.OpenForm "frm_letter_of_indemnity",
acNormal, , "policy_number = '" & strpolicynumber & "' and
start_date = '" & strstartdate & "'"

When the start_date is text field in the table then
everything seems to work fine. But when the start_date is
a date field in the table I get the "OpenForm Action was
Cancelled" error. I need to have the start date as a date
field for other date caculations in the program.

All help appreciated-Tim B

DoCmd.OpenForm "frm_letter_of_indemnity", acNormal, , _
"policy_number = '" & strpolicynumber & _
"' and start_date = #" & _
Format(strstartdate, "mm/dd/yyyy") & "#"

That's assuming strstartdate is an intelligible representation of a date
value.
 
DoCmd.OpenForm "frm_letter_of_indemnity", acNormal, , _
"policy_number = '" & strpolicynumber & _
"' and start_date = #" & _
Format(strstartdate, "mm/dd/yyyy") & "#"

That's assuming strstartdate is an intelligible representation of a date
value.

I have tried declaring strstartdate as a string and as a
date and I can't get either to work. The declaration
statements look like this.

dim strstartdate as Date
dim strstartdate as String

I have two copies of the database trying to work on each
side so the declaration statements are not in the same
database. The str naming convention was just a habit when
I was naming all the variables for the program.
 
Thanks!!!!
-----Original Message-----


DoCmd.OpenForm "frm_letter_of_indemnity", acNormal, , _
"policy_number = '" & strpolicynumber & _
"' and start_date = #" & _
Format(strstartdate, "mm/dd/yyyy") & "#"

That's assuming strstartdate is an intelligible representation of a date
value.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
 
Tim B said:
I have tried declaring strstartdate as a string and as a
date and I can't get either to work. The declaration
statements look like this.

dim strstartdate as Date
dim strstartdate as String

I have two copies of the database trying to work on each
side so the declaration statements are not in the same
database. The str naming convention was just a habit when
I was naming all the variables for the program.

Most people interpret a "str" prefix on a variable as indicating that it
has a data type of String.
 
Back
Top