View Full Version : Events not working my way


jwindon
08-26-2001, 03:01 PM
I used an excerise in one of my books to make command buttons do: AddRecord, Edit Record and Save Record. The ViewForm is set to AllowEdits=False and AllowAdditions=False and AllowDeletions=False.

The buttons do their job, changing properties just fine to allow edits and saving, but the AddRecord gives me the error "Cannot go to that record". The Code DOES turn the AllowAdditions to True before moving to acNewRecord.

In addition, I wanted the AllowEdits, etc. to go back to read-only properties when moving in between records. I put in on the OnCurrentEvent. It doesn't work.

I guess the problem is somehow related to a combobox called FastFind that looks up the corresponding controls based on its selection (Option 3 of the ComboBox wizard). If the form is read-only, I cannot use the combobox. I already changed it's property to OnFocus, Combobox, AllowEdits=True

What am I doing wrong? Besides being long-winded.

R. Hicks
08-26-2001, 03:07 PM
Be much simpler to troubleshoot the code you are using. Post the code you are using, sounds like you have a line being executed out of the needed order.

RDH

jwindon
08-26-2001, 03:14 PM
RDH. I think you maybe right. I don't have the database here at home though. Let me see what I can do from scratch.

Form event: OnCurrent:

Me.AllowEdits=False
Me.Combo1.Unlocked

CommandButton event: OnClick:

Me.AllowAdditions=True
Me.AllowEdits=True
DoCmd.GotoRecord , , acNewRecord
SetFocus.District

Well, Ok I see a problem with that alreay, the AllowEdits will go back to False if I goto another record...??? but the error comes up before I even get to a blank record.


[This message has been edited by jwindon (edited 08-26-2001).]

R. Hicks
08-26-2001, 03:46 PM
For your cmdbuton:

Private Sub YourCmdButton_Click()
Me.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
Me.District.SetFocus
End Sub

Now for the On Current event:

Private Sub Form_Current()
If Me.NewRecord Then
Me.AllowEdits = True
Else
Me.AllowEdits = False
End If
End Sub

You have a combobox in your example that you are unlocking in the On Current event. Not sure why you are doing this????

Anyway the syntax to control this would be:

Me.YourComboName.Locked = False ' to unlock it
Me.YourComboName.Locked = True ' to lock it

HTH
RDH

[This message has been edited by R. Hicks (edited 08-26-2001).]