Programming Asst. Needed - Check Box

J

JK

I have a check box (access03) on a workorders form. I also have a date field
called DatePickedUp. If the work being done is done in the field, I have no
use for this field. So, I have a check box and if the check box is selected,
it disables the DatePickedUp field and automatically insers 1/1/1900 into
that field.

The code I pasted below works perfectly if it's an existing record. If
however, I'm creating a new record and I uncheck the FieldRepair check box to
specify the work being done is being done in-house, the form automatically
creates a new record. If I click the FieldReport check box five times, I'll
find five newly created records applied to that specific customer.

I also have a problem when deleting a record from this form. When I try to
delete a record, the form goes blank - all fields dissapear rather than
goinging to the next existing record or onto a new record. I have the form's
control source set directly to the workorders table.

Any advice would be great. -- thx.

Private Sub FieldRepair_AfterUpdate()

'Grey Date Pickedup Field if Checked (FieldRepair)

Dim bLock As Boolean
bLock = Nz(Me.FieldRepair, True)
Me.[DatePickedUp].Locked = bLock

If Me!FieldRepair = False Then
Forms!Workorders![DatePickedUp] = Null
'Me.cmdDatePickedUp.Enabled = True
Else
'Me.cmdDatePickedUp.Enabled = False
End If
End Sub


Private Sub FieldRepair_Click()

' Declare a variable to hold the current record's key.
Dim vMyControlValue As Variant

' Save the current record's key.
vMyControlValue = Me.WorkorderID

' Requery the form.
Me.Requery

' Find the record whose key we saved.
Me.Recordset.FindFirst "WorkorderID=" & vMyControlValue

'Auto insert 1/1/1900 into the DatePickedUp Field if (FieldRepair)is
checked...
If Me!FieldRepair = True Then
Forms!Workorders![DatePickedUp] = #1/1/1900#
Else
' If you need code to achieve your other alternative,
' put it here. If not, you can delete the "Else" statement.
End If
End Sub


Form_Current
Call FieldRepair_AfterUpdate
 
J

JK

I located one of the problems - I should have found this earlier. I have it
set in my double-click event going into the workorders form:

The allow additions part was active. I commented it out and now my form
works as far as deleting and adding new records.

I still can't seem to get my check box working properly.

Private Sub ViewData()

'open workorder form to record that was dbl-clicked

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Workorders"
stLinkCriteria = "[WorkorderID]=" & Me![WorkorderID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

'disallow additions - disables page up/dn and mousewheel
'Forms.Workorders.AllowAdditions = False

End Sub
 

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

Top