Open Form Where Condition (1 Viewer)

JustinS

Member
Local time
Today, 16:11
Joined
Apr 11, 2020
Messages
58
I am using the following code to open a form in my application. However, I am getting a 3075 error code. When I isolate the first portion of the Where clause the command works. Which leaves me wondering what I am doing incorrectly with the rest of the code.

DoCmd.OpenForm "Commercial Electric Claim Stats", acNormal, , "[Unit 1 ID]=" & Me.ID & "OR" & " [Unit 2 ID]=" & Me.ID & "OR" & "[Unit 3 ID]=" & Me.ID

Any suggestions you guys might have would be greatly appreciated.
 

moke123

AWF VIP
Local time
Today, 16:11
Joined
Jan 11, 2013
Messages
3,926
you may need spaces before and after "OR" like " OR "
 

JustinS

Member
Local time
Today, 16:11
Joined
Apr 11, 2020
Messages
58
I tried both methods without any luck. The problem seems to be with the "OR" because if I substitute "AND" the statement works. Is there a rule against using "OR" in the where clause on the open form command? If so, is there a work around to this?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:11
Joined
Oct 29, 2018
Messages
21,485
I tried both methods without any luck. The problem seems to be with the "OR" because if I substitute "AND" the statement works. Is there a rule against using "OR" in the where clause on the open form command? If so, is there a work around to this?
Did you try what @Gasman suggested? Try it this way and tell us (or post a screenshot) what you get.
Code:
Dim strCriteria As String
strCriteria = "[Unit 1 ID]=" & Me.ID & "OR" & " [Unit 2 ID]=" & Me.ID & "OR" & "[Unit 3 ID]=" & Me.ID
MsgBox strCriteria
DoCmd.OpenForm "Commercial Electric Claim Stats", acNormal, , strCriteria
 

JustinS

Member
Local time
Today, 16:11
Joined
Apr 11, 2020
Messages
58
I copied and pasted into the sub routine as specified and I got a 3075 error, see attached
 

Attachments

  • Where.JPG
    Where.JPG
    59.8 KB · Views: 163

theDBguy

I’m here to help
Staff member
Local time
Today, 13:11
Joined
Oct 29, 2018
Messages
21,485
I copied and pasted into the sub routine as specified and I got a 3075 error, see attached
Hi @JustinS. Try commenting out all your code and just use the one I gave you.

In the image you posted, it doesn't look like you used the MsgBox line I suggested.

This will help us help you troubleshoot the problem.
 

JustinS

Member
Local time
Today, 16:11
Joined
Apr 11, 2020
Messages
58
I did as you guys suggested and received the same error. Here are the screenshots, they will probably be more helpful this time. Thanks for the help guys.
 

Attachments

  • criteria.JPG
    criteria.JPG
    138.8 KB · Views: 177
  • msgbox.JPG
    msgbox.JPG
    15.4 KB · Views: 175

theDBguy

I’m here to help
Staff member
Local time
Today, 13:11
Joined
Oct 29, 2018
Messages
21,485
I did as you guys suggested and received the same error. Here are the screenshots, they will probably be more helpful this time. Thanks for the help guys.
Thanks for the update. That's why @Gasman suggested you check what the criteria was ending up being.

As @moke123 was saying, not having spaces around your ORs is probably messing you up. For example, you screenshot has this snippet:

[Unit 1 ID]=456OR

That doesn't make sense to Access. Have you tried adding spaces around your ORs as suggested earlier?

In other word, use " OR " instead of just "OR".
 

JustinS

Member
Local time
Today, 16:11
Joined
Apr 11, 2020
Messages
58
I added the spaces which makes the string more legible as suggested. As you can see it makes the string more legible, but I still get the same error. I don't get an error if I replace OR with AND, but obviously the sub doesn't work correctly. Is there something about the open form command that doesn't like OR?
 

Attachments

  • criteria2.JPG
    criteria2.JPG
    130.8 KB · Views: 162
  • msgbox2.JPG
    msgbox2.JPG
    16.3 KB · Views: 113

theDBguy

I’m here to help
Staff member
Local time
Today, 13:11
Joined
Oct 29, 2018
Messages
21,485
I added the spaces which makes the string more legible as suggested. As you can see it makes the string more legible, but I still get the same error. I don't get an error if I replace OR with AND, but obviously the sub doesn't work correctly. Is there something about the open form command that doesn't like OR?
Well, at least that's one issue we know is fixed. Now, click on the Debug button on the error message you're getting and then post a screenshot of the result.
 

JustinS

Member
Local time
Today, 16:11
Joined
Apr 11, 2020
Messages
58
Still points to the open form command.
 

Attachments

  • debug.JPG
    debug.JPG
    45.1 KB · Views: 174

theDBguy

I’m here to help
Staff member
Local time
Today, 13:11
Joined
Oct 29, 2018
Messages
21,485
Still points to the open form command.
That's fine. We're still trying to trace the problem at this point.

So, do you really have a form with that name? Just as a test, try removing the criteria and see if the problem still occurs.

Code:
DoCmd.OpenForm "Commercial Electric Claim Stats"

Or, try it this way.

Code:
DoCmd.OpenForm "[Commercial Electric Claim Stats]"
 

JustinS

Member
Local time
Today, 16:11
Joined
Apr 11, 2020
Messages
58
I think something has been corrupted. I went back to a previous version and the same code is working correctly. That is what was so perplexing about this issue is that this command had been functioning perfect for the last several months. It just started giving me problems yesterday. Thanks for the help, but I think the quickest thing is to just revert back to a previous version and rebuild.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:11
Joined
Oct 29, 2018
Messages
21,485
I think something has been corrupted. I went back to a previous version and the same code is working correctly. That is what was so perplexing about this issue is that this command had been functioning perfect for the last several months. It just started giving me problems yesterday. Thanks for the help, but I think the quickest thing is to just revert back to a previous version and rebuild.
Hi. Sounds like a plan. Good luck with your project.
 

Users who are viewing this thread

Top Bottom