odd order of events

simeon_rose

Registered User.
Local time
Today, 00:00
Joined
Nov 4, 2000
Messages
34
hi, i've got code that ensures that people enter data shown in a certain textbox into another textbox correctly by displaying an error message and then resetting the focus. the code i've got usually works fine...but then on adding another command button that closes the current form and then opens another one. after this button's addition, the code no longer works properly. if wrong data is entered, the focus gets set to the new command button and the error message doesn't get displayed until that button's event procedure is run. what is going on?
 
the code behind the error message is:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull(Me.Text21) Or Me.Text21 <> Me.Mini_ID Then
Cancel = True
MsgBox "Incorrect Entry, You should enter " & Forms!frmaddadvertiser!Mini_ID, 0, "Error"
Mini_ID.SetFocus

End If

the code behind the button that opens and closes the forms together is:

Private Sub Command25_Click()

DoCmd.OpenForm "frmaddadmin", acNormal, , , acAdd, acNormal
DoCmd.Close acForm, "frmaddadvertiser"

End Sub

seperately, without both being on the same form, the code is correct - everything runs as it should, i only get this 'clash' when both functions are on the same form.

thank you.
 
I could very easily be talking out of my backside here, but it looks like the Cancel = true is interacting with your command button. Personaly upon opening the form (ie in OnOpen) I would set the focus to Text21, then in the LostFocus event of Text21, (as according to your code Mini_ID has the original data => Text21 needs to be completed) I would carry out the checking code, but without the line Cancel = True.

Then again why don't you just have Me.Text21 = Me.Mini_ID on the OnOpen function?
 
Have you tried reversing the sequence ie. DoCmd.Close
DoCmd.Open
Might be worth a try.
 
sorry to keep on hassling you, but this problem just will not go away. i've tried your suggestions, but still i get the same annoying hitch. i liked the idea suggested by simongallop of simply making the Mini_ID textbo equa top the display of Text21, but the suggested syntax to carry out this operation must be flawed, it still doesn't work. is there any way i can work on this suggestion, or perhaps, just solve my old problem?
 
The problem lies in the fact that you procedure runs in the Before Update event - this does not occur when you leave the control - try On Lose Focus
 
What happens if they don't tab into the control? My suggestion is to move the code from the before update and attach it to the command button
Private Sub Command25_Click()
If IsNull(Me.Text21) Or Me.Text21 <> Me.Mini_ID Then
Cancel = True
MsgBox "Incorrect Entry, You should enter " & Forms!frmaddadvertiser!Mini_ID, 0, "Error"
Mini_ID.SetFocus

Exit Sub
Else:
DoCmd.OpenForm "frmaddadmin", acNormal, , , acAdd, acNormal
DoCmd.Close acForm, "frmaddadvertiser"

End If
End Sub
If you do this you will have to remove the close x from the form.
 

Users who are viewing this thread

Back
Top Bottom