Can I use 'AND' in the macro statement?

  • Thread starter Thread starter John F.
  • Start date Start date
J

John F.

I need the subsequent form to open taking into account the value of 2 fields
on the 'calling form' that the button the code is attached to is on. I've
written a 'WHERE' statement that looks like:
-"[Firstfield] ="& [Firstfield] $" AND [Secondfield] =" $[Secondfield]

(the Wizard gave me the first part but I had to suply he 'Secondfiled' part
myself. Both fields are represented by textboxes with values displayed on the
calling form)

When I run the macro, it treats the [Secondfield] as a parameter.

Can I Ues the 'AND' statement? How do I do it effectively? Do the referred
fields on the calling form have to be in the primary key of the underying
table? THis is a problem since it's a querty with not primay key that is the
underlying structure.

Thank you.

John Fowler.
 
John,

Yes, you can certainly do what you are asking. However, I am not sure
of your syntax there, whether your $ signs are a typo in your newsgroup
post, or whether you have copy/pasted from your macro. Also there are
some spaces in the wrong place. Therefore, more like this:
"[Firstfield]=" & [Firstfield] & " AND [Secondfield]=" & [Secondfield]

This would assume both fields are numbers. If not, the syntax would be
different. For example, if Firstfield is numerical and Secondfield is
text, you would need:
"[Firstfield]=" & [Firstfield] & " AND [Secondfield]='" & [Secondfield]
& "'"
 
Thank you, Steve. That clarified several issues for me.

John F.

Steve Schapel said:
John,

Yes, you can certainly do what you are asking. However, I am not sure
of your syntax there, whether your $ signs are a typo in your newsgroup
post, or whether you have copy/pasted from your macro. Also there are
some spaces in the wrong place. Therefore, more like this:
"[Firstfield]=" & [Firstfield] & " AND [Secondfield]=" & [Secondfield]

This would assume both fields are numbers. If not, the syntax would be
different. For example, if Firstfield is numerical and Secondfield is
text, you would need:
"[Firstfield]=" & [Firstfield] & " AND [Secondfield]='" & [Secondfield]
& "'"

--
Steve Schapel, Microsoft Access MVP
I need the subsequent form to open taking into account the value of 2 fields
on the 'calling form' that the button the code is attached to is on. I've
written a 'WHERE' statement that looks like:
-"[Firstfield] ="& [Firstfield] $" AND [Secondfield] =" $[Secondfield]

(the Wizard gave me the first part but I had to suply he 'Secondfiled' part
myself. Both fields are represented by textboxes with values displayed on the
calling form)

When I run the macro, it treats the [Secondfield] as a parameter.

Can I Ues the 'AND' statement? How do I do it effectively? Do the referred
fields on the calling form have to be in the primary key of the underying
table? THis is a problem since it's a querty with not primay key that is the
underlying structure.

Thank you.

John Fowler.
 
Back
Top