2 If statment On Current with Docmd.Openform (1 Viewer)

evictme

Registered User.
Local time
Today, 03:05
Joined
May 18, 2011
Messages
168
Hello guys,

Im kind of stuck with an operation I'm trying to make happen in the On Current event of a form I have:

So far what I have, that is functioning exactly the way i need, is the following
[
Private Sub Form_Current()
On Error Resume Next

Me![ImageFrame].picture = Me![picture]
If LockBoundControls([Form], False) Then
LockBoundControls([Form], True) = True
Else
LockBoundControls([Form], True) = True
End If

End Sub
]
I need this because this form locks so there are no accidental typos when searching and to load a picture assigned to a record but I would also like to add to this that when the form loads it checks the status of the record and if it meets a certain criteria it will open another form to a record of the matching unique ID, the following is what I came up with and tried to add at the end of the above statement as follows:

[
End If
If Me.Status = "On Vacation" Or "On Leave" Then
DoCmd.OpenForm "Employee Time Off Request", , , "EmployeeID = " & Me.EmployeeID
End If
End Sub
]
After several attempts and several different configurations of the two pieces I have not been successful.

Each time it will load the current record of the Me. form but it will also pop up the other form, no matter what i do. What I need is for the other form to load only if the criteria is met.

I have a sneaking suspicion that it may be due to the fact that the form locks on current but I dont know and have exhausted my other research avenues in attempts to find a solution.

I appreciate you taking the time to read this and any help you can give me.

thanks,
 

evictme

Registered User.
Local time
Today, 03:05
Joined
May 18, 2011
Messages
168
bump...

no one has some suggestions for me?
 

JHB

Have been here a while
Local time
Today, 09:05
Joined
Jun 17, 2012
Messages
7,732
Your problem lay here:
If Me.Status = "On Vacation" Or "On Leave" Then

It has to be:
If Me.Status = "On Vacation" Or Me.Status = "On Leave" Then

Because you have this error handling "On Error Resume Next", you not got the error massage, else you would have figured out that "Or "On Leave" was not the right syntax.
Mostly it is a good idea, to strip out all error handling, when you are developing until it runs perfect.
 

joemach

Registered User.
Local time
Today, 04:05
Joined
Sep 10, 2012
Messages
22
Definitely agree with getting rid of "On Error Resume Next". That will make debugging a nightmare. You can not find the line throwing the error. Also, no error handling until the code runs without any error. That way when it does trow an error you know what error to trap and how to proceed.

Take out the "On Error Resume Next" and let us know the line that gets highlighted and the error code.

HTH
 

Users who are viewing this thread

Top Bottom