Error 2105

G

Guest

I am getting an error (2105) in the following code:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim strList As String
Dim intLen As Integer
Dim strSelectedRecord As Variant
Dim strOSUser As String

strList = ""

If Recruitment.Value = True And Me.lstProviderType.ItemsSelected.Count =
0 Then
MsgBox "Please select a provider type." _
, vbExclamation + vbOKOnly, "PROVIDER TYPE"
lstProviderType.SetFocus
Exit Sub
ElseIf Recruitment.Value = True And
Me.lstProviderType.ItemsSelected.Count > 0 Then
For Each strSelectedRecord In lstProviderType.ItemsSelected
strList = strList + lstProviderType.Column(1, strSelectedRecord)
& ","
Next strSelectedRecord

intLen = Len(strList)

[Provider Type] = Left(strList, intLen - 1)
End If

strOSUser = modPR_Stats.fOSUserName

[Modified By].Value = strOSUser
[Modified Date].Value = Now()

End Sub

I checked the MS knowledge db and here is what it says:

CAUSE
Microsoft Access cannot perform the specified command because the
BeforeUpdate event procedure is still running. This is true even if the
Cancel parameter is set to True or if a CancelEvent macro attempts to cancel
the action.

RESOLUTION
Instead of setting the Cancel parameter to True, or using the CancelEvent
action, use a SendKeys statement if that is an option with the command you
are trying to use. The SendKeys statement sends keystrokes to the Microsoft
Access buffer, where they wait until the BeforeUpdate event procedure is
finished.


I'm thinking there is better solution to the problem. Any ideas are
appreciated. Thanks in advance.
 
W

Wayne Morgan

The main thing I see is that you don't Cancel when you Exit Sub to make a
correction, so the Update continues.
If Recruitment.Value = True And Me.lstProviderType.ItemsSelected.Count
=
0 Then
MsgBox "Please select a provider type." _
, vbExclamation + vbOKOnly, "PROVIDER TYPE"
lstProviderType.SetFocus Cancel = True
Exit Sub

--
Wayne Morgan
MS Access MVP


xRoachx said:
I am getting an error (2105) in the following code:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim strList As String
Dim intLen As Integer
Dim strSelectedRecord As Variant
Dim strOSUser As String

strList = ""

If Recruitment.Value = True And Me.lstProviderType.ItemsSelected.Count
=
0 Then
MsgBox "Please select a provider type." _
, vbExclamation + vbOKOnly, "PROVIDER TYPE"
lstProviderType.SetFocus
Exit Sub
ElseIf Recruitment.Value = True And
Me.lstProviderType.ItemsSelected.Count > 0 Then
For Each strSelectedRecord In lstProviderType.ItemsSelected
strList = strList + lstProviderType.Column(1,
strSelectedRecord)
& ","
Next strSelectedRecord

intLen = Len(strList)

[Provider Type] = Left(strList, intLen - 1)
End If

strOSUser = modPR_Stats.fOSUserName

[Modified By].Value = strOSUser
[Modified Date].Value = Now()

End Sub

I checked the MS knowledge db and here is what it says:

CAUSE
Microsoft Access cannot perform the specified command because the
BeforeUpdate event procedure is still running. This is true even if the
Cancel parameter is set to True or if a CancelEvent macro attempts to
cancel
the action.

RESOLUTION
Instead of setting the Cancel parameter to True, or using the CancelEvent
action, use a SendKeys statement if that is an option with the command you
are trying to use. The SendKeys statement sends keystrokes to the
Microsoft
Access buffer, where they wait until the BeforeUpdate event procedure is
finished.


I'm thinking there is better solution to the problem. Any ideas are
appreciated. Thanks in advance.
 
G

Guest

Thanks Wayne. I tried adding Cancel to the code but still received the same
error. The rest of the code does what I need it to except the user gets the
error every time.

Wayne Morgan said:
The main thing I see is that you don't Cancel when you Exit Sub to make a
correction, so the Update continues.
If Recruitment.Value = True And Me.lstProviderType.ItemsSelected.Count
=
0 Then
MsgBox "Please select a provider type." _
, vbExclamation + vbOKOnly, "PROVIDER TYPE"
lstProviderType.SetFocus Cancel = True
Exit Sub

--
Wayne Morgan
MS Access MVP


xRoachx said:
I am getting an error (2105) in the following code:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim strList As String
Dim intLen As Integer
Dim strSelectedRecord As Variant
Dim strOSUser As String

strList = ""

If Recruitment.Value = True And Me.lstProviderType.ItemsSelected.Count
=
0 Then
MsgBox "Please select a provider type." _
, vbExclamation + vbOKOnly, "PROVIDER TYPE"
lstProviderType.SetFocus
Exit Sub
ElseIf Recruitment.Value = True And
Me.lstProviderType.ItemsSelected.Count > 0 Then
For Each strSelectedRecord In lstProviderType.ItemsSelected
strList = strList + lstProviderType.Column(1,
strSelectedRecord)
& ","
Next strSelectedRecord

intLen = Len(strList)

[Provider Type] = Left(strList, intLen - 1)
End If

strOSUser = modPR_Stats.fOSUserName

[Modified By].Value = strOSUser
[Modified Date].Value = Now()

End Sub

I checked the MS knowledge db and here is what it says:

CAUSE
Microsoft Access cannot perform the specified command because the
BeforeUpdate event procedure is still running. This is true even if the
Cancel parameter is set to True or if a CancelEvent macro attempts to
cancel
the action.

RESOLUTION
Instead of setting the Cancel parameter to True, or using the CancelEvent
action, use a SendKeys statement if that is an option with the command you
are trying to use. The SendKeys statement sends keystrokes to the
Microsoft
Access buffer, where they wait until the BeforeUpdate event procedure is
finished.


I'm thinking there is better solution to the problem. Any ideas are
appreciated. Thanks in advance.
 
W

Wayne Morgan

Have you put a break point in the code to halt it then step through it to
see where the error is?
 
W

Wayne Morgan

[Provider Type] = Left(strList, intLen - 1)
End If

strOSUser = modPR_Stats.fOSUserName

[Modified By].Value = strOSUser
[Modified Date].Value = Now()

In the above, the items you're assigning values to, are they the names of
fields or the names of controls on the form. If they aren't, make them the
names of bound controls on the form and put "Me." in front of them to see
what happens.

Example:
Me.[Provider Type] = Left(strList, intLen - 1)
 

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