syntax error missing operator-open frm to spec. record

B

babs

Here is my code attached to the onclick event of a command button:
Private Sub Command12_Click()
On Error GoTo Err_Command12_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Jeff Employee Info with Sched"
DoCmd.OpenForm stDocName, , , "[man name]=" &
Me!JeffSchedLookAheadGenerate.Form!cbomanname
DoCmd.Maximize

Exit_Command12_Click:
Exit Sub

Err_Command12_Click:
MsgBox Err.Description
Resume Exit_Command12_Click

End Sub

I am trying to navigate to Jeff Employee info with Sched form
to the specific Man name that is presently active on the subform of the
present form the control name of the man name on the subform is cbomanname
and the subform name is JeffSchedLookAheadGenerate - I think I am missing
quotes - had some and got a different error - looked up syntax help - can't
figure it out.

thanks,
barb
 
D

Dirk Goldgar

babs said:
Here is my code attached to the onclick event of a command button:
Private Sub Command12_Click()
On Error GoTo Err_Command12_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Jeff Employee Info with Sched"
DoCmd.OpenForm stDocName, , , "[man name]=" &
Me!JeffSchedLookAheadGenerate.Form!cbomanname
DoCmd.Maximize

Exit_Command12_Click:
Exit Sub

Err_Command12_Click:
MsgBox Err.Description
Resume Exit_Command12_Click

End Sub

I am trying to navigate to Jeff Employee info with Sched form
to the specific Man name that is presently active on the subform of the
present form the control name of the man name on the subform is
cbomanname
and the subform name is JeffSchedLookAheadGenerate - I think I am missing
quotes - had some and got a different error - looked up syntax help -
can't
figure it out.

If, as I gather, [man name] is a text field, you need quotes around the
value you build into the criteria string. Try this:

DoCmd.OpenForm stDocName, , , _
"[man name]=" & Chr(34) & _
Me!JeffSchedLookAheadGenerate.Form!cbomanname & _
Chr(34)

The function expression Chr(34) returns the double-quote character (").
 
B

babs

Wow - its works thanks - I am not used to using the Chr(34) can you replace
it with """ quotes around a quote - just wondering for a better
understanding?
thanks,
barb

Dirk Goldgar said:
babs said:
Here is my code attached to the onclick event of a command button:
Private Sub Command12_Click()
On Error GoTo Err_Command12_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Jeff Employee Info with Sched"
DoCmd.OpenForm stDocName, , , "[man name]=" &
Me!JeffSchedLookAheadGenerate.Form!cbomanname
DoCmd.Maximize

Exit_Command12_Click:
Exit Sub

Err_Command12_Click:
MsgBox Err.Description
Resume Exit_Command12_Click

End Sub

I am trying to navigate to Jeff Employee info with Sched form
to the specific Man name that is presently active on the subform of the
present form the control name of the man name on the subform is
cbomanname
and the subform name is JeffSchedLookAheadGenerate - I think I am missing
quotes - had some and got a different error - looked up syntax help -
can't
figure it out.

If, as I gather, [man name] is a text field, you need quotes around the
value you build into the criteria string. Try this:

DoCmd.OpenForm stDocName, , , _
"[man name]=" & Chr(34) & _
Me!JeffSchedLookAheadGenerate.Form!cbomanname & _
Chr(34)

The function expression Chr(34) returns the double-quote character (").

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)
 
D

Dirk Goldgar

babs said:
Wow - its works thanks - I am not used to using the Chr(34) can you
replace
it with """ quotes around a quote - just wondering for a better
understanding?


The problem is that, in order to quote a quote and have the VB compiler make
any sense of it, you need to double-up the quotes. So if I have this
literal string:

Dirk says "Hi."

to put it in quotes I have write this:

"Dirk says ""Hi."""

One double-quote character, quoted, becomes """". You can always build your
strings that way, if you prefer it to Chr(34), but it becomes hard to read
and interpret. The equivalent to the OpenForm statement I posted before,
using that sort of quoting, would be:

DoCmd.OpenForm stDocName, , , _
"[man name]=""" & _
Me!JeffSchedLookAheadGenerate.Form!cbomanname & _
""""

That's perfectly valid, but I always have to count the quotes very
carefully.

Another alternative is to define a constant to represent the double-quote
character, and use that wherever you need to put a quote into a string:

' In some standard module's Declaration section:
Public Const Q As String = """"

' In your code where you need to quote something:
DoCmd.OpenForm stDocName, , , _
"[man name]=" & _
Q & Me!JeffSchedLookAheadGenerate.Form!cbomanname & Q
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top