Code only works in break mode

  • Thread starter Thread starter Jordan Brice
  • Start date Start date
J

Jordan Brice

I have a function called DisableEnable that runs on the
OnCurrent and AfterUpdate events on all my forms. Its job
is to enable/disable certain controls depending on the
task e.g adding a new record disables the next/previous
buttons, and unlocks the appropriate controls for data
entry.

The problem I'm having is that the code only executes
properly either in break mode when I step through the
function manually, or after I load the form, then go to
design mode, and then back to form mode. I can't for the
life of me figure this out, so any help would be most
appreciated.

Thanks in advance

Jordan
 
I forgot to mention that I'm using MS-Access 2000 on
Windows NT. Here's the function code:


Public Function DisableEnable(frm As Form)
Dim rstClone As DAO.Recordset
Set rstClone = frm.RecordsetClone
Select Case frm.Name
Case "planting":
If frm.NewRecord Then
new_p_record:
frm!prev_plant.Visible = False
frm!next_plant.Visible = False
frm!save_plant.Visible = True
frm!cancel_plant.Visible = True
frm!Job_Number.SetFocus
frm!new_plant.Visible = False
frm!Job_Number.SetFocus
frm!Job_Number.Locked = False
frm!Job_Number.Text = jobno(workorder)
frm!Job_Number.Locked = True
frm!Tree_Planted.SetFocus
frm!Tree_Planted.Locked = False
frm!Species.SetFocus
frm!Species.Locked = False
frm!Diameter.SetFocus
frm!Diameter.Locked = False
frm!Billed.SetFocus
frm!Billed.Locked = False
frm!Condition.SetFocus
frm!Condition.Locked = False
frm!Date_Completed.SetFocus
frm!Date_Completed.Locked = False
frm!HouseID.SetFocus
frm!HouseID.Locked = False
frm!HouseID.Text = str(HouseIDnbr)
frm!HouseID.Locked = True
frm!Species.SetFocus
Exit Function
End If
Select Case rstClone.RecordCount
Case 0:
GoTo new_p_record:
Case 1:
frm!Date_Completed.SetFocus
frm!prev_plant.Enabled = False
frm!Date_Completed.SetFocus
frm!next_plant.Enabled = False
Case Else
rstClone.bookmark =
frm.bookmark 'Sets the "clone" to the same record the
form is on

rstClone.MovePrevious 'moves the "clone"
back one record
If rstClone.BOF Then
frm!prev_plant.Enabled = False
Else
frm!prev_plant.Enabled = True
End If
rstClone.bookmark =
frm.bookmark 'resets the "clone" position to be the
same as the form

rstClone.MoveNext 'moves the "clone"
forward one record
If rstClone.EOF Then
frm!Date_Completed.SetFocus
frm!next_plant.Enabled = False
Else
frm!Date_Completed.SetFocus
frm!next_plant.Enabled = True
End If
If rstClone.BOF Then
frm!Date_Completed.SetFocus
frm!prev_plant.Enabled = False
End If
End Select
Case "pruning":
If frm.NewRecord Then
new_t_record:
frm!prev_prune.Visible = False
frm!next_prune.Visible = False
frm!save_prune.Visible = True
frm!cancel_prune.Visible = True
frm!Job_Number.SetFocus
frm!new_prune.Visible = False
frm!Job_Number.SetFocus
frm!Job_Number.Locked = False
frm!Job_Number.Text = jobno(workorder)
frm!Job_Number.Locked = True
frm!Pruning_Type.SetFocus
frm!Pruning_Type.Locked = False
frm!Tree_Pruned.SetFocus
frm!Tree_Pruned.Locked = False
frm!Date_Completed.SetFocus
frm!Date_Completed.Locked = False
frm!HouseID.SetFocus
frm!HouseID.Locked = False
frm!HouseID.Text = str(HouseIDnbr)
frm!HouseID.Locked = True
frm!Pruning_Type.SetFocus
Exit Function
End If
Select Case rstClone.RecordCount
Case 0:
GoTo new_t_record:
Case 1:
frm!Date_Completed.SetFocus
frm!prev_prune.Enabled = False
frm!Date_Completed.SetFocus
frm!next_prune.Enabled = False
Case Else
rstClone.bookmark = frm.bookmark
rstClone.MovePrevious
If rstClone.BOF Then
frm!Date_Completed.SetFocus
frm!prev_prune.Enabled = False
Else
frm!Date_Completed.SetFocus
frm!prev_prune.Enabled = True
End If
rstClone.bookmark = frm.bookmark
rstClone.MoveNext
If rstClone.EOF Then
frm!Date_Completed.SetFocus
frm!next_prune.Enabled = False
Else
frm!Date_Completed.SetFocus
frm!next_prune.Enabled = True
End If
End Select
Case "removal":
If frm.NewRecord Then
new_r_record:
frm!prev_remove.Visible = False
frm!next_remove.Visible = False
frm!save_remove.Visible = True
frm!cancel_remove.Visible = True
frm!Job_Number.SetFocus
frm!new_remove.Visible = False
frm!Job_Number.SetFocus
frm!Job_Number.Locked = False
frm!Job_Number.Text = jobno(workorder)
frm!Job_Number.Locked = True
frm!Tree_Removed.SetFocus
frm!Tree_Removed.Locked = False
frm!Date_Completed.SetFocus
frm!Approved.SetFocus
frm!Approved.Locked = False
frm!Reason.SetFocus
frm!Reason.Locked = False
frm!Replant.SetFocus
frm!Replant.Locked = False
frm!Species.SetFocus
frm!Species.Locked = False
frm!Location_Adjustment.SetFocus
frm!Location_Adjustment.Locked = False
frm!HouseID.Visible = True
frm!HouseID.SetFocus
frm!HouseID.Locked = False
frm!HouseID.Text = str(HouseIDnbr)
frm!HouseID.Locked = True
frm!Tree_Removed.SetFocus
Exit Function
End If
Select Case rstClone.RecordCount
Case 0:
GoTo new_r_record:
Case 1:
frm!Date_Completed.SetFocus
frm!prev_remove.Enabled = False
frm!Date_Completed.SetFocus
frm!next_remove.Enabled = False
Case Else
rstClone.bookmark = frm.bookmark
rstClone.MovePrevious
If rstClone.BOF Then
frm!Date_Completed.SetFocus
frm!prev_remove.Enabled = False
Else
frm!Date_Completed.SetFocus
frm!next_remove.Enabled = True
End If
rstClone.bookmark = frm.bookmark
rstClone.MoveNext
If rstClone.EOF Then
frm!Date_Completed.SetFocus
frm!next_remove.Enabled = False
Else
frm!Date_Completed.SetFocus
frm!next_remove.Enabled = True
End If
End Select
Case "address":
If frm.NewRecord Then
new_a_record:
frm!Areanum.SetFocus
frm!Areanum.Locked = False
frm!Housenum.SetFocus
frm!Housenum.Locked = False
frm!Block.SetFocus
frm!Block.Locked = False
frm!Street.SetFocus
frm!Street.Locked = False
frm!Street_Type.SetFocus
frm!Street_Type.Locked = False
frm!Zip.SetFocus
frm!Zip.Locked = False
frm!Phone.SetFocus
frm!Phone.Locked = False
frm!Renter_Occupied.SetFocus
frm!Renter_Occupied.Locked = False
frm!Owner_Name.SetFocus
frm!Owner_Name.Locked = False
frm!Map.SetFocus
frm!Map.Locked = False
frm!Quadrant.SetFocus
frm!Quadrant.Locked = False
frm!show_remove.Visible = False
frm!show_planting.Visible = False
frm!show_prune.Visible = False
frm!Num_Trees.SetFocus
frm!Num_Trees.Locked = False
frm!Lawn_Width.SetFocus
frm!Lawn_Width.Locked = False
frm!Utilities.SetFocus
frm!Utilities.Locked = False
frm!save_address.Visible = True
frm!cancel_address.Visible = True
frm!prev_address.Visible = False
frm!next_address.Visible = False
frm!new_address.Visible = False
frm!Areanum.SetFocus
Exit Function
End If
Select Case rstClone.RecordCount
Case 0:
GoTo new_a_record:
Case 1:
frm!Areanum.SetFocus
frm!prev_address.Enabled = False
frm!Areanum.SetFocus
frm!next_address.Enabled = False
Case Else
rstClone.bookmark = frm.bookmark
rstClone.MovePrevious
If rstClone.BOF Then
frm!Areanum.SetFocus
frm!prev_address.Enabled = False
Else
frm!Areanum.SetFocus
frm!prev_address.Enabled = True
End If
rstClone.bookmark = frm.bookmark
rstClone.MoveNext
If rstClone.EOF Then
frm!Areanum.SetFocus
frm!next_address.Enabled = False
Else
frm!Areanum.SetFocus
frm!next_address.Enabled = True
End If
End Select
End Select
End Function
 
Back
Top