We have all seen this error message~
The expression On Click you entered as the event property setting produced the following error:
The expression may not result in the name of a macro, the name of a user-defined function, or a stored procedure
There may have been an error evaluating the function, event, or macro.
It usually happens when your vba code is seriously flawed.
I have a product that I distribute to dozens of laptop users. This is a COMPILED product (an mde). The error happens when the user presses a certain button. This button uploads records from their laptop to an SQL Server database. Here are some details:
1. There are two groups of users, group A and group B. Almost all of the errors happen to group B. Group A runs windowsXP group B runs Windows 2000. Group A are domain users on our lan. Group B are authenticated users.
2. Even with Group B, most of the uploads ARE successful. Their uploads fail about 40% of the time.
3. Here is a code snippet:
Public Function uploadComments()
'create some objects
Dim counter As Integer
counter = 0
Dim cmd As New ADODB.Command
Dim serverConn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim localConn As New ADODB.Connection
Dim prmComments As New ADODB.Parameter
Dim prmWeekStartDate As New ADODB.Parameter
Dim prmWindowsID As New ADODB.Parameter
'Configure the parameters.
With prmComments
.name = "@comments"
.Type = adChar
.Direction = adParamInput
.Size = 2500
End With
With prmWeekStartDate
.name = "@weekStartDate"
.Type = adDate
.Direction = adParamInput
End With
With prmWindowsID
.name = "@windowsID"
.Type = adChar
.Direction = adParamInput
.Size = 50
End With
'Open the server connection.
'For some reason, you must do this prior to configuring cmd.
serverConn.Open [connection string]
'Configure the cmd.
With cmd
.ActiveConnection = serverConn
.CommandText = "[stored procedure name]"
.CommandType = adCmdStoredProc
.CommandTimeout = 10
.Parameters.Append prmComments
.Parameters.Append prmWeekStartDate
.Parameters.Append prmWindowsID
End With
'Open the LOCAL connection.
localConn.Open [connection string]
'Configure the recordset object, and fill it with records.
With rs
.ActiveConnection = localConn
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.Open "Select * from commentsFor1PayPeriod"
End With
'Actually upload the records.
Do While counter < rs.RecordCount
prmComments.value = rs(0).value
prmWeekStartDate.value = rs(1).value
prmWindowsID.value = [user ID]
cmd.execute
rs.Move 1
counter = counter + 1
Loop
'Clean up
Set cmd = Nothing
localConn.Close
serverConn.Close
End Function
The expression On Click you entered as the event property setting produced the following error:
The expression may not result in the name of a macro, the name of a user-defined function, or a stored procedure
There may have been an error evaluating the function, event, or macro.
It usually happens when your vba code is seriously flawed.
I have a product that I distribute to dozens of laptop users. This is a COMPILED product (an mde). The error happens when the user presses a certain button. This button uploads records from their laptop to an SQL Server database. Here are some details:
1. There are two groups of users, group A and group B. Almost all of the errors happen to group B. Group A runs windowsXP group B runs Windows 2000. Group A are domain users on our lan. Group B are authenticated users.
2. Even with Group B, most of the uploads ARE successful. Their uploads fail about 40% of the time.
3. Here is a code snippet:
Public Function uploadComments()
'create some objects
Dim counter As Integer
counter = 0
Dim cmd As New ADODB.Command
Dim serverConn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim localConn As New ADODB.Connection
Dim prmComments As New ADODB.Parameter
Dim prmWeekStartDate As New ADODB.Parameter
Dim prmWindowsID As New ADODB.Parameter
'Configure the parameters.
With prmComments
.name = "@comments"
.Type = adChar
.Direction = adParamInput
.Size = 2500
End With
With prmWeekStartDate
.name = "@weekStartDate"
.Type = adDate
.Direction = adParamInput
End With
With prmWindowsID
.name = "@windowsID"
.Type = adChar
.Direction = adParamInput
.Size = 50
End With
'Open the server connection.
'For some reason, you must do this prior to configuring cmd.
serverConn.Open [connection string]
'Configure the cmd.
With cmd
.ActiveConnection = serverConn
.CommandText = "[stored procedure name]"
.CommandType = adCmdStoredProc
.CommandTimeout = 10
.Parameters.Append prmComments
.Parameters.Append prmWeekStartDate
.Parameters.Append prmWindowsID
End With
'Open the LOCAL connection.
localConn.Open [connection string]
'Configure the recordset object, and fill it with records.
With rs
.ActiveConnection = localConn
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.Open "Select * from commentsFor1PayPeriod"
End With
'Actually upload the records.
Do While counter < rs.RecordCount
prmComments.value = rs(0).value
prmWeekStartDate.value = rs(1).value
prmWindowsID.value = [user ID]
cmd.execute
rs.Move 1
counter = counter + 1
Loop
'Clean up
Set cmd = Nothing
localConn.Close
serverConn.Close
End Function