On Enter code error on subform

T

Tara

I have a subform and I'm trying to run some code in the On Enter event that
tells the user that the field is only used under certain conditions and then
resets the focus back to a different control. I know you can't diable
controls on subforms so I thought my solution would in essence produce the
same result. However, I'm getting an error message that I don't understand.
It says: "The expression On Enter you entered as the event property setting
produced the following error: A problem occurred while Microsoft Access was
communicating with the OLE server or Active X control" It goes on the
mention that the expression may be result in the name of a macro, etc or
there may have been an error evaluating the function, etc.

Here's the code I have in the On Enter event of the control:

Private Sub Score_Enter()

Dim intResponse As Integer
Dim strMsg As String

If Me.ToolID = 2 Then
strMsg = "The score field can only be used in conjunction with the
Edinburgh Scale."
intReponse = MsgBox(strMsg, vbOKOnly)
If intReponse = vbOKOnly Then
Me.SetFocus.ToolID

End Sub
 
S

Stuart McCall

Tara said:
I have a subform and I'm trying to run some code in the On Enter event that
tells the user that the field is only used under certain conditions and
then
resets the focus back to a different control. I know you can't diable
controls on subforms so I thought my solution would in essence produce the
same result. However, I'm getting an error message that I don't
understand.
It says: "The expression On Enter you entered as the event property
setting
produced the following error: A problem occurred while Microsoft Access
was
communicating with the OLE server or Active X control" It goes on the
mention that the expression may be result in the name of a macro, etc or
there may have been an error evaluating the function, etc.

Here's the code I have in the On Enter event of the control:

Private Sub Score_Enter()

Dim intResponse As Integer
Dim strMsg As String

If Me.ToolID = 2 Then
strMsg = "The score field can only be used in conjunction with the
Edinburgh Scale."
intReponse = MsgBox(strMsg, vbOKOnly)
If intReponse = vbOKOnly Then
Me.SetFocus.ToolID

End Sub

You're missing two End If statements. Try this:

Private Sub Score_Enter()

Dim intResponse As Integer
Dim strMsg As String

If Me.ToolID = 2 Then
strMsg = "The score field can only be used in conjunction with the
Edinburgh Scale."
intReponse = MsgBox(strMsg, vbOKOnly)
If intReponse = vbOKOnly Then
Me.SetFocus.ToolID
End If
End If

End Sub
 
J

John W. Vinson

I have a subform and I'm trying to run some code in the On Enter event that
tells the user that the field is only used under certain conditions and then
resets the focus back to a different control. I know you can't diable
controls on subforms so I thought my solution would in essence produce the
same result. However, I'm getting an error message that I don't understand.
It says: "The expression On Enter you entered as the event property setting
produced the following error: A problem occurred while Microsoft Access was
communicating with the OLE server or Active X control" It goes on the
mention that the expression may be result in the name of a macro, etc or
there may have been an error evaluating the function, etc.

Here's the code I have in the On Enter event of the control:

Private Sub Score_Enter()

Dim intResponse As Integer
Dim strMsg As String

If Me.ToolID = 2 Then
strMsg = "The score field can only be used in conjunction with the
Edinburgh Scale."
intReponse = MsgBox(strMsg, vbOKOnly)
If intReponse = vbOKOnly Then
Me.SetFocus.ToolID

End Sub

When you view the properties of the field does the On Enter property on the
Events tab show [Event Procedure]? It should; this error suggests that
something else has crept in.
 
T

Tara

Thanks for the help Stuart. I can't believe I forgot the End If's.
Unfortunately, there must be something else wrong too because it still didn't
work.
 
T

Tara

John, yes, it does say [Event Procedure]. Any ideas what is happening?

Thanks for any help!

John W. Vinson said:
I have a subform and I'm trying to run some code in the On Enter event that
tells the user that the field is only used under certain conditions and then
resets the focus back to a different control. I know you can't diable
controls on subforms so I thought my solution would in essence produce the
same result. However, I'm getting an error message that I don't understand.
It says: "The expression On Enter you entered as the event property setting
produced the following error: A problem occurred while Microsoft Access was
communicating with the OLE server or Active X control" It goes on the
mention that the expression may be result in the name of a macro, etc or
there may have been an error evaluating the function, etc.

Here's the code I have in the On Enter event of the control:

Private Sub Score_Enter()

Dim intResponse As Integer
Dim strMsg As String

If Me.ToolID = 2 Then
strMsg = "The score field can only be used in conjunction with the
Edinburgh Scale."
intReponse = MsgBox(strMsg, vbOKOnly)
If intReponse = vbOKOnly Then
Me.SetFocus.ToolID

End Sub

When you view the properties of the field does the On Enter property on the
Events tab show [Event Procedure]? It should; this error suggests that
something else has crept in.
 
S

Stuart McCall

Tara said:
Thanks for the help Stuart. I can't believe I forgot the End If's.
Unfortunately, there must be something else wrong too because it still
didn't
work.

Hi Tara

I think I've got it. This line:

Me.SetFocus.ToolID

should read:

Me.ToolID.SetFocus
 
T

Tara

When I read your response, I thought you had figured it out it too. So, I
changed it, but there's still something wrong. It's still giving me the same
error message. I just can't figure it out. Any more thoughts?
 
S

Stuart McCall

Tara said:
When I read your response, I thought you had figured it out it too. So, I
changed it, but there's still something wrong. It's still giving me the
same
error message. I just can't figure it out. Any more thoughts?

Let's see the code as you have it now, so we're definitely on the same page.
 
T

Tara

Thanks so much for all the help Stuart. Here's the code:

Private Sub Score_Enter()
Dim intResponse As Integer
Dim strMsg As String

If Me.ToolID = 2 Then
strMsg = "The score field can only be used in conjunction with the
Edinburgh Scale."
intReponse = MsgBox(strMsg, vbOKOnly)
If intReponse = vbOKOnly Then
Me.ToolID.SetFocus
End If

End If

End Sub
 
S

Stuart McCall

Tara said:
Thanks so much for all the help Stuart. Here's the code:

Private Sub Score_Enter()
Dim intResponse As Integer
Dim strMsg As String

If Me.ToolID = 2 Then
strMsg = "The score field can only be used in conjunction with the
Edinburgh Scale."
intReponse = MsgBox(strMsg, vbOKOnly)
If intReponse = vbOKOnly Then
Me.ToolID.SetFocus
End If

End If

End Sub
<snip>

Well the only thing I can see that's wrong (well not necessarily wrong, but
not best practice) is the use of MsgBox as a function when the only result
it can return is vbOKOnly. All you really need is:

MsgBox strMsg

You can remove the:

If intReponse = vbOKOnly Then

(and its corresponding End If, of course!).

So the code could look like:

Private Sub Score_Enter()
Dim strMsg As String

If Me.ToolID = 2 Then
strMsg = "The score field can only be used in " _
& "conjunction with the Edinburgh Scale."
MsgBox strMsg
Me.ToolID.SetFocus
End If

End Sub

and there's certainly nothing there that could cause your problem.

If you still get an error, please post the line the code breaks on.
 
S

Stuart McCall

Tara said:
My code doesn't even start to execute when I get the error...
<snip>

So when (or should I say under what conditions) does the error occur?

Also, can you compile the project? (In the VBE, Debug -> Compile)
 
T

Tara

It happens as soon as I enter the textbox, but the code doesn't break when I
step through it.

Yes, I can compile it.

This is driving me crazy! It's not a something I HAVE to do, meaning it's
not integral to the project, but I'd really like to do it this way if at all
possible.

Thanks for all your help.
 
S

Stuart McCall

Tara said:
It happens as soon as I enter the textbox, but the code doesn't break when
I
step through it.

Yes, I can compile it.

This is driving me crazy! It's not a something I HAVE to do, meaning it's
not integral to the project, but I'd really like to do it this way if at
all
possible.

Thanks for all your help.

When the error message appears, what line are you taken to when you click
'Debug'?
 
T

Tara

I started getting the message as I worked on other parts of the DB yesterday,
so then I started thinking corruption. I ended up importing everything into
a new DB and so far I'm no longer getting an error anywhere in the DB, so
that's good. However, the code we've been talking about still isn't working.
It doesn't give an error message. It just doesn't do anything at all,
almost like it's not firing.
 
S

Stuart McCall

Tara said:
I started getting the message as I worked on other parts of the DB
yesterday,
so then I started thinking corruption. I ended up importing everything
into
a new DB and so far I'm no longer getting an error anywhere in the DB, so
that's good. However, the code we've been talking about still isn't
working.
It doesn't give an error message. It just doesn't do anything at all,
almost like it's not firing.
<snip>

Ah. Corruption. Well at least now you've eliminated the main culprit.

Some things to check:

Make sure your subform is called Score.
Make sure Score has [Event Procedure] in it's Enter property.
When you run the app, make sure ToolID does in fact contain 2 before you
enter the subform.

Other than that I can't think of anything that would prevent the code from
executing.
 
T

Tara

Wanted to follow up with you Stuart and thank you for all of your help! I
finally got it working, thanks to you. You pointed me toward the final
problem in your last post, which was making sure ToolID had 2. It should've
said if ToolID was 1. So finally it's all finished. I really appreciate you
continuing to check in on this with me, you helped tremendously along the way.

Stuart McCall said:
Tara said:
I started getting the message as I worked on other parts of the DB
yesterday,
so then I started thinking corruption. I ended up importing everything
into
a new DB and so far I'm no longer getting an error anywhere in the DB, so
that's good. However, the code we've been talking about still isn't
working.
It doesn't give an error message. It just doesn't do anything at all,
almost like it's not firing.
<snip>

Ah. Corruption. Well at least now you've eliminated the main culprit.

Some things to check:

Make sure your subform is called Score.
Make sure Score has [Event Procedure] in it's Enter property.
When you run the app, make sure ToolID does in fact contain 2 before you
enter the subform.

Other than that I can't think of anything that would prevent the code from
executing.
 
S

Stuart McCall

Tara said:
Wanted to follow up with you Stuart and thank you for all of your help! I
finally got it working, thanks to you. You pointed me toward the final
problem in your last post, which was making sure ToolID had 2. It
should've
said if ToolID was 1. So finally it's all finished. I really appreciate
you
continuing to check in on this with me, you helped tremendously along the
way.
<snip>

Great! I'm glad to have helped. Hope the rest of the app develops smoothly
(it won't - you do know that, right? Just kidding.)
 
S

shawnrad

<snip>

Great! I'm glad to have helped. Hope the rest of the app develops smoothly
(it won't - you do know that, right? Just kidding.)

I am having the same problem and have read through this string of
messages. Since I know next to nothing about VBA (I copied & pasted
the coding that orignally worked in my db but no longer does), can you
please tell me if importing the tables was the solution to the
original error message about the OLE Server communicating with the
Active X control?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top