DoCmd.OpenForm

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm still trying to open a form to a specific record. In a form, tI have a button who's OnClick event opens another form. I can get it to open the form to the first record, but not to the specific record I want. Following is the DoCmd line

DoCmd.OpenForm "frmNewEmp", , strWhereCategory

where the strWhereCategory statement is

"EmployeeID = 07042

This is a valid EmployeeID number but it doesn't open the form to that record. What am I missing

tia
JMorrell
 
Based on the fact that your EmployeeID is 07042, I suspect that it is a text
field. If that is true, then you need to embed some quotation marks around
it in your string for strWhereCategory.

strWhereCategory = "EmployeeID = " & Chr(34) & "07042" & Chr(34)

or, if you are reading the EmployeeID value from your current form:

strWhereCategory = "EmployeeID = " & Chr(34) & Me!EmployeeID & Chr(34)


hth,
--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


JMorrell said:
I'm still trying to open a form to a specific record. In a form, tI have
a button who's OnClick event opens another form. I can get it to open the
form to the first record, but not to the specific record I want. Following
is the DoCmd line:
 
I should have mentioned how I created strWhereCategory

strWhereCategory = "EmployeeID = " & EmployeeID & "

and yes, it is a text field. I'm confused at to your "Chr(34)" ?

I feel that I'm very close on this.

----- Cheryl Fischer wrote: ----

Based on the fact that your EmployeeID is 07042, I suspect that it is a tex
field. If that is true, then you need to embed some quotation marks aroun
it in your string for strWhereCategory

strWhereCategory = "EmployeeID = " & Chr(34) & "07042" & Chr(34

or, if you are reading the EmployeeID value from your current form

strWhereCategory = "EmployeeID = " & Chr(34) & Me!EmployeeID & Chr(34


hth
-

Cheryl Fischer, MVP Microsoft Acces
Law/Sys Associates, Houston, T


JMorrell said:
I'm still trying to open a form to a specific record. In a form, tI hav
a button who's OnClick event opens another form. I can get it to open th
form to the first record, but not to the specific record I want. Followin
is the DoCmd line
 
Chr(34) is the character code for a double-quote. I use it because I feel
it is more readable, easily identifiable as a double-quote and eliminates
the need for me to count single and/or double quotation marks when debugging
code. When the expression I provided to you is evaluated when you open the
form, it will be evaluated as:

EmployeeID = "07042"
 
Got it to work finally. The Chr(34) works great but I had to add a third comma to the DoCmd statement to finally make it work

Thanks for all your help!
 
Good! Thank you for posting your results and good luck with your project.

--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


JMorrell said:
Got it to work finally. The Chr(34) works great but I had to add a third
comma to the DoCmd statement to finally make it work.
 
Back
Top