From: Jon on 24 Jan 2010 18:41 Thank you John. Yes... I had left it out and of course that does mean that the form doesn't move on to the next record! I had cut and paste from one of many versions. Although inserting cancel = true does solve the record navigation issue I still have the original problem of Error 2501 (Run cmd action cancelled). I am now down to testing on a new database with 1 table, 3 fields, two records just to make sure that there is no extraneous coding etc! What is so odd is that the standard access form navigation buttons work absolutely as expected. It is the navigation button created by the wizard that do not work. Equally, a save record button created by the wizard doesn't work with the validation code as expected. (error 2501 again) Any more ideas? "John W. Vinson" wrote: > On Sat, 23 Jan 2010 16:33:01 -0800, Jon <Jon(a)discussions.microsoft.com> wrote: > > >Private Sub Form_BeforeUpdate(Cancel As Integer) > > > > If (IsNull(Me.txtEmail) Or Me.txtEmail = "") And Me.EMailMailings = -1 > >Then > > MsgBox "You must enter an email address to be able to select 'By > >Email' communications for this record.", vbInformation, "Data Validation" > > Me.EMailMailings = False > > Me.txtEmail.SetFocus > > End If > > > >End Sub > > > >The standard access form navigation buttons all work as expected with the > >beforeupdate code. The 'next record' button on the form however still does > >not work as expected. The msg fires and the 'ok' takes the form to the next > >record. By inserting breakpoints, what appears to be happening is that the > >code never goes to the error handling section. Instead it just exits on the > >Exit Sub line > > > >Very puzzzled now! > > There is no error, so you won't go to the error section (which, as far as that > goes, does not exist). > > What you left out is setting the Cancel argument to True when you discover a > problem. Doing so will prevent the record from being saved and allow the > setfocus to take effect. Just put a line > > Cancel = True > > on any line between the Then and the End If. > -- > > John W. Vinson [MVP] > . >
From: John W. Vinson on 24 Jan 2010 21:56 On Sun, 24 Jan 2010 15:41:01 -0800, Jon <Jon(a)discussions.microsoft.com> wrote: > I >still have the original problem of Error 2501 (Run cmd action cancelled). Trap and ignore the error: On Error GoTo Proc_Error <your code> Proc_Exit: Exit Sub Proc_Error: Select Case Err.Number Case 2501 Resume Proc_Exit Case Else MsgBox "Error " & Err.Number & " in MySubName:" _ & vbCrLr & Err.Description Resume Proc_Exit End Select End Sub -- John W. Vinson [MVP]
From: BruceM via AccessMonster.com on 25 Jan 2010 07:47 I use MoveNext because it is more compact, and it seems to do the same thing as DoCmd syntax for basic navigation. There are arguments available for DoCmd.GoToRecord that may not be available for MoveNext. I have searched for a while on this topic, but it is difficult to frame the search string, so I am not much the wiser for my investigations, except to say that they seem to confirm that for basic navigation there is no real difference. If somebody with definitive information on the topic can provide clarification I would be interested in hearing about it. Jon wrote: >Thank you everyone for your time on this. > >Bruce... your suggestions on logic may well makes sense and i will look at >implementing them when basic problem is solved. Do your code suggestions for >navigation and saving have any particular advantages? > >On the core problem I may now add to the mystery.... or clarify. I have now >started from scratch with a new simple form with a text field, check box and >'move to next record' button created by wizard. The Form also has the >standard access form navigation buttons at the bottom. Its about as basic a >form as possible and the data validation should be a pretty basic piece of >code... I thought! > >The only code behand the form is now: > >Private Sub Command2_Click() >On Error GoTo Err_Command2_Click > > DoCmd.RunCommand acCmdSaveRecord > Me.Recordset.MoveNext > >Exit_Command2_Click: > Exit Sub > >Err_Command2_Click: > Select Case Err.Number > Case 3314, 2101, 2115, 2501, 2105 > 'do nothing > Case Else > MsgBox Err.Description > End Select > Resume Exit_Command2_Click > >End Sub > >Private Sub Form_BeforeUpdate(Cancel As Integer) > > If (IsNull(Me.txtEmail) Or Me.txtEmail = "") And Me.EMailMailings = -1 >Then > MsgBox "You must enter an email address to be able to select 'By >Email' communications for this record.", vbInformation, "Data Validation" > Me.EMailMailings = False > Me.txtEmail.SetFocus > End If > >End Sub > >The standard access form navigation buttons all work as expected with the >beforeupdate code. The 'next record' button on the form however still does >not work as expected. The msg fires and the 'ok' takes the form to the next >record. By inserting breakpoints, what appears to be happening is that the >code never goes to the error handling section. Instead it just exits on the >Exit Sub line > >Very puzzzled now! > >> This is sort of dodging the problem, but it seems to me there are three >> possibilities: >[quoted text clipped - 48 lines] >> >> >> >> >> . -- Message posted via http://www.accessmonster.com
From: Jon on 25 Jan 2010 17:53 Dear John Sorry! No go. All code for form is as now below; its very similar to Allen's original suggestion. (pasted with save command commented out) With the Save command back in I get 2501 (RunCmd action was cancelled). Without it I get 2105 (Can't go to specific record). This occurs with or without error trapping code... ie it makes no difference. As I say the standard access navigation buttons work fine with the beforeupdate property. Can soemoene explain why? Could I be missing a libaray reference? Private Sub Form_BeforeUpdate(Cancel As Integer) If (IsNull(Me.Email) Or Me.Email = "") And Me.ByEmail = -1 Then MsgBox "You must enter an email address to be able to select 'By Email' communications for this record.", vbInformation, "Data Validation" Me.ByEmail = False Me.Email.SetFocus Cancel = True End If End Sub Private Sub Command8_Click() On Error GoTo Proc_Error 'DoCmd.RunCommand acCmdSaveRecord DoCmd.GoToRecord , , acNext Proc_Exit: Exit Sub Proc_Error: Select Case Err.Number Case 2105 Resume Proc_Exit Case Else MsgBox "Error " & Err.Number & " in MySubName:" _ & vbCrLr & Err.Description Resume Proc_Exit End Select End Sub This very weird. "John W. Vinson" wrote: > On Sun, 24 Jan 2010 15:41:01 -0800, Jon <Jon(a)discussions.microsoft.com> wrote: > > > I > >still have the original problem of Error 2501 (Run cmd action cancelled). > > Trap and ignore the error: > > On Error GoTo Proc_Error > <your code> > Proc_Exit: > Exit Sub > Proc_Error: > Select Case Err.Number > Case 2501 > Resume Proc_Exit > Case Else > MsgBox "Error " & Err.Number & " in MySubName:" _ > & vbCrLr & Err.Description > Resume Proc_Exit > End Select > End Sub > -- > > John W. Vinson [MVP] > . >
First
|
Prev
|
Pages: 1 2 3 4 Prev: How to tell what form a sub-form is in. Next: Force Sub Report to Show Even If No Data |