I've never used an IF clause in Access SQL. I've only used IF in Oracle to define functions and whatnot.
I have a form that has a listbox based on a query. This form is called twice depending on 2 textboxes from another form. I was wondering if I could do this so I wouldn't have 2 of the same forms with almost the same SQL statement.
I was wondering if I could do something similar to:
Is something like this possible?
Otherwise I think this might work:
..This way does work; I still haven't tested the first way yet (no time); maybe someone knows if you can do IF statements in a WHERE
I have a form that has a listbox based on a query. This form is called twice depending on 2 textboxes from another form. I was wondering if I could do this so I wouldn't have 2 of the same forms with almost the same SQL statement.
I was wondering if I could do something similar to:
Code:
SELECT *
FROM [Table Name]
WHERE
(
IF ([Forms]![Form Name]![Text Box1].Value is null)
THEN
WHERE ([Table Name].[ID]=[Forms]![Form Name]![Text Box1].Value
ELSE
WHERE ([Table Name].[ID]=[Forms]![Form Name]![Text Box2].Value
);
Otherwise I think this might work:
Code:
SELECT *
FROM [Table Name]
WHERE
(
(
[Forms]![Form Name]![Text Box1].Value is null AND
[Table Name].[ID]=[Forms]![Form Name]![Text Box1].Value
)
OR
(
[Forms]![Form Name]![Text Box1].Value is not null AND
[Table Name].[ID]=[Forms]![Form Name]![Text Box2].Value
)
);
..This way does work; I still haven't tested the first way yet (no time); maybe someone knows if you can do IF statements in a WHERE
Last edited: