Normally I would expect to take that type of action in the form's before
update event and not in the Close event.
I would guess that you have a form + subform arrangement and that is the
problem you are trying to overcome. If using the UNLOAD event does not work I
would try running an SQL update query. You would need to store the primary
key of the main form in a variable.
Roughly the code might look like the following UNTESTED code.
DIM PKValue as Long 'Assuming the primary key is a number
Private Sub Form_BeforeUpdate(Cancel As Integer)
'Store the current value of the primary key
PKValue = Me.PkField
End Sub
In the Unload event or the close event try the following.
Private Sub Form_Unload(Cancel As Integer)
'Build and execute an update query to update the field on the
'specified record.
Dim StrSQL as string
strSQL = "UPDATE [OrdersTable] SET [Order Complete] = True" & _
"WHERE [PkField] = " & PkValue
CurrentDb().Execute strSQL
End Sub
John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
Phil Freihofner wrote:
> I think, I'm not sure, but by the time the OnClose Event occurs, the
> underlying data table is no longer attached to the form. You might try using
> the form's "Unload" event as a trigger instead, as this is a bit early in the
> sequence of things.
>
> In the opposite direction, I do know that one normally doesn't have access
> to the values in the form's controls at the "Open" event, but they are
> present at the "Load" event. So maybe it is the same during the closing
> process.
>
> Best of luck!
>
> "Wavequation" wrote:
>
>> I am trying to change the value in a check box using code. The control is a
>> check box named "Order Complete", and is bound to a field in a table, also
>> named "Order Complete", with a field type of yes/no. The control is enabled,
>> and not locked, and may be changed by clicking in it. The code is triggered
>> by the "on close" event. On close of the form, I would like the value of the
>> underlying field to become "yes". The code I am using to do this is as
>> follows:
>>
>> Me.Order_Complete = True
>>
>> When the code runs, it gives an error message:
>>
>> run-time error '2147352567(80020009)'
>> You can't assign a value to this object
>>
>> Why can't the value of this control be changed?
>> Thanks!
>>
>>
|