Or statements in event procedures

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

Guest

I have a button on form "teachers" (containing field ID) which I want to open
a form "projects" (containing fields id1 and id2) where either id1 or id2 = id

I have a button which opens "projects" when id =id1, and one which opens for
id2=id. The obvious solution would be just to incoroprate an or statement
into the event procedure, but I don't know the syntax.

Can anyone help?
 
If form teachers still open when projects is open, then change the
RecordSource of projects to link to the id in form teachers

Select * From MyTable Where Id1 = Forms![teachers]![Id] or Id2 =
Forms![teachers]![Id]
 
I've looked at altering this, but it looks like it would mean destroying the
existing relationship between the form and it's underlying table, which I
don't want to do, as I want to open it at other times filtering by different
criteria.

This is the visual basic that access has given me

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FRM Projects"

stLinkCriteria = "[Lead Author ID]=" & Me![Teacher ID]

DoCmd.OpenForm stDocName, , , stLinkCriteria

I need to find a way of changing "[Lead Author ID]" to "[Lead Author ID] or
[Co-Author ID]" without mucking up the syntax


Ofer said:
If form teachers still open when projects is open, then change the
RecordSource of projects to link to the id in form teachers

Select * From MyTable Where Id1 = Forms![teachers]![Id] or Id2 =
Forms![teachers]![Id]

Rhysickle said:
I have a button on form "teachers" (containing field ID) which I want to open
a form "projects" (containing fields id1 and id2) where either id1 or id2 = id

I have a button which opens "projects" when id =id1, and one which opens for
id2=id. The obvious solution would be just to incoroprate an or statement
into the event procedure, but I don't know the syntax.

Can anyone help?
 
Change your line:

stLinkCriteria = "[Lead Author ID]=" & Me![Teacher ID]

to the following (all on one line):

stLinkCriteria = "([Lead Author ID]=" & Me![Teacher ID] & ") Or
([Co-Author ID]=" & Me![Teacher ID] & ")"

You need to put the Or operator between two expressions that could stand
alone. The parentheses are unnecessary, but aid in readability.

HTH,

Kevin
I've looked at altering this, but it looks like it would mean destroying the
existing relationship between the form and it's underlying table, which I
don't want to do, as I want to open it at other times filtering by different
criteria.

This is the visual basic that access has given me

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FRM Projects"

stLinkCriteria = "[Lead Author ID]=" & Me![Teacher ID]

DoCmd.OpenForm stDocName, , , stLinkCriteria

I need to find a way of changing "[Lead Author ID]" to "[Lead Author ID] or
[Co-Author ID]" without mucking up the syntax


:

If form teachers still open when projects is open, then change the
RecordSource of projects to link to the id in form teachers

Select * From MyTable Where Id1 = Forms![teachers]![Id] or Id2 =
Forms![teachers]![Id]

:

I have a button on form "teachers" (containing field ID) which I want to open
a form "projects" (containing fields id1 and id2) where either id1 or id2 = id

I have a button which opens "projects" when id =id1, and one which opens for
id2=id. The obvious solution would be just to incoroprate an or statement
into the event procedure, but I don't know the syntax.

Can anyone help?
 
Back
Top