Help with Error Message? (1 Viewer)

hollyquinn

Registered User.
Local time
Today, 04:17
Joined
Oct 7, 2008
Messages
17
Hi. I am having an issue with an Access database. There is a certain form in the database that we are getting some error messages on. The first error message is:

Access failed to evaluate one or more expressions because 'Enabled' was referenced in an expression. Only functions and properties that are considered to be safe are allowed in expression when Access runs in sandbox mode.

Someone else here changed the macro security settings to low and that resolved the first error message. Now we are getting this error message:

The expression Before Update you entered in the event property setting produced the following error: The Save action was canceled.
* The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure]
*There may have been an error evaluating the function, event, or macro.

I'll post the module code below and maybe someone can help? My knowledge of VBA is very basic and I just can't find the error. I've been searching for over an hour. Here's the code:

Option Compare Database
Option Explicit
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me.BidPeriod) And IsNull(Me.Crew) Then
MsgBox "Please enter data for BOTH the the Bid Period and Crew Group, or blank for both!" _
& Chr(10) & " " _
& Chr(10) & "ASOK requires a Bid Period and a Crew Group to update the Training Schedule Matrix.", vbCritical + vbOKOnly, "ASOK Session Save"
Me.BidPeriod = Null
Me.Crew = Null
Cancel = True
Exit Sub
End If
If IsNull(Me.BidPeriod) And Not IsNull(Me.Crew) Then
MsgBox "Please enter data for BOTH the the Bid Period and Crew Group, or blank for both!" _
& Chr(10) & " " _
& Chr(10) & "ASOK requires a Bid Period and a Crew Group to update the Training Schedule Matrix.", vbCritical + vbOKOnly, "ASOK Session Save"
Me.BidPeriod = Null
Me.Crew = Null
Cancel = True
Exit Sub
End If
DoCmd.Save
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Not IsNull(Me.BidPeriod) And IsNull(Me.Crew) Then
MsgBox "Please enter data for BOTH the the Bid Period and Crew Group, or blank for both!" _
& Chr(10) & " " _
& Chr(10) & "ASOK requires a Bid Period and a Crew Group to update the Training Schedule Matrix.", vbCritical + vbOKOnly, "ASOK Session Save"
Me.BidPeriod = Null
Me.Crew = Null
Cancel = True
Exit Sub
End If
If IsNull(Me.BidPeriod) And Not IsNull(Me.Crew) Then
MsgBox "Please enter data for BOTH the the Bid Period and Crew Group, or blank for both!" _
& Chr(10) & " " _
& Chr(10) & "ASOK requires a Bid Period and a Crew Group to update the Training Schedule Matrix.", vbCritical + vbOKOnly, "ASOK Session Save"
Me.BidPeriod = Null
Me.Crew = Null
Cancel = True
Exit Sub
End If
DoCmd.Save
End Sub


Any help would be so awesome. Thanks in advance. :confused:
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 09:17
Joined
Sep 12, 2006
Messages
15,667
pit a breakpoint in it - click the margin by the first stement in the sub - you should get a brown blob

when the code runs it will stop at this point - use f8 to step thru a line at a time, and see exactly what is going on
 

HiTechCoach

Well-known member
Local time
Today, 03:17
Joined
Mar 6, 2006
Messages
4,357
You don't need to save the form at this point so remove this from both events.

Code:
DoCmd.Save

If you are trying to save the record with this line, you show not do this here since you are already in the process of saving the data.

You can also simplify the code like this:

Code:
Option Compare Database
Option Explicit

Private Sub Form_BeforeUpdate(Cancel As Integer)

If (Not IsNull(Me.BidPeriod) And IsNull(Me.Crew)) or (IsNull(Me.BidPeriod) And Not IsNull(Me.Crew) ) Then

MsgBox "Please enter data for BOTH the the Bid Period and Crew Group, or blank for both!" _
& Chr(10) & " " _
& Chr(10) & "ASOK requires a Bid Period and a Crew Group to update the Training Schedule Matrix.", vbCritical + vbOKOnly, "ASOK Session Save"

Me.BidPeriod = Null
Me.Crew = Null
Cancel = True

End If

End Sub


Private Sub Form_Unload(Cancel As Integer)


If (Not IsNull(Me.BidPeriod) And IsNull(Me.Crew)) or (IsNull(Me.BidPeriod) And Not IsNull(Me.Crew) ) Then

MsgBox "Please enter data for BOTH the the Bid Period and Crew Group, or blank for both!" _
& Chr(10) & " " _
& Chr(10) & "ASOK requires a Bid Period and a Crew Group to update the Training Schedule Matrix.", vbCritical + vbOKOnly, "ASOK Session Save"

Me.BidPeriod = Null
Me.Crew = Null
Cancel = True

End If


End Sub
 
Last edited:

hollyquinn

Registered User.
Local time
Today, 04:17
Joined
Oct 7, 2008
Messages
17
pit a breakpoint in it - click the margin by the first stement in the sub - you should get a brown blob

when the code runs it will stop at this point - use f8 to step thru a line at a time, and see exactly what is going on

Hi, thanks for helping. When I try to debug and click on run it prompts me to run a macro but displays no macros in the available list. I'm not sure how to proceed?

I'm a little confused too. Why would changing the security level to low from medium cause the code to finally throw an error?
 

hollyquinn

Registered User.
Local time
Today, 04:17
Joined
Oct 7, 2008
Messages
17
You don't need to save the form at this point so remove this from both events.

Code:
DoCmd.Save

If you are trying to save the record with this line, you show not do this here since you are already in the process of saving the data.

You can also simplify the code like this:

Code:
Option Compare Database
Option Explicit
 
Private Sub Form_BeforeUpdate(Cancel As Integer)
 
If (Not IsNull(Me.BidPeriod) And IsNull(Me.Crew)) or (IsNull(Me.BidPeriod) And Not IsNull(Me.Crew) ) Then
 
MsgBox "Please enter data for BOTH the the Bid Period and Crew Group, or blank for both!" _
& Chr(10) & " " _
& Chr(10) & "ASOK requires a Bid Period and a Crew Group to update the Training Schedule Matrix.", vbCritical + vbOKOnly, "ASOK Session Save"
 
Me.BidPeriod = Null
Me.Crew = Null
Cancel = True
 
End If
 
End Sub
 
 
Private Sub Form_Unload(Cancel As Integer)
 
 
If (Not IsNull(Me.BidPeriod) And IsNull(Me.Crew)) or (IsNull(Me.BidPeriod) And Not IsNull(Me.Crew) ) Then
 
MsgBox "Please enter data for BOTH the the Bid Period and Crew Group, or blank for both!" _
& Chr(10) & " " _
& Chr(10) & "ASOK requires a Bid Period and a Crew Group to update the Training Schedule Matrix.", vbCritical + vbOKOnly, "ASOK Session Save"
 
Me.BidPeriod = Null
Me.Crew = Null
Cancel = True
 
End If
 
 
End Sub

Hi, Thanks for your reply. I will give that a try. I didn't actually write this code that's why I'm having such a hard time with it. I'm going to ask you the same question that I asked gemma-the-husky: Why would changing the security level to low from medium cause the code to finally throw an error?

I'm going to give you suggestions a try though. Thanks.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 09:17
Joined
Sep 12, 2006
Messages
15,667
does it compile - that sort of error often points to some strange compile error

and have you got option explicit set - it might be some rogue variable name
 

krishan.chawla

New member
Local time
Today, 01:17
Joined
Dec 21, 2008
Messages
6
HI

I want to delete import/export specifications from access 2003 database. Please suggest me. It is urgent need for my project.
 

Users who are viewing this thread

Top Bottom