Re: Proper way to save a record
- From: Pat Dools <PatDools@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 27 Jun 2005 17:49:02 -0700
Hi Albert,
Thanks for your response. One of the things I am trying to accomplish in
addition to checking for required fields and calling up a new record is to
give the user an informative error message if they try to enter a record with
identical 'key' field info. If I don't do the 'DoCmd.RunCommand
acCmdSaveRecord' (see code below), all the user sees is, 'You can't go to the
specified record'. The error message tells the user the exact problem
(duplicate key) when I have the following code. Is this a reasonably
efficient way to do this? Thx. (Code below):
Private Sub CommandOpenNewRecord_Click()
If Len(Me.site.Value & "") = 0 Then
MsgBox "You must enter a value into Site Number."
Me.site.SetFocus
ElseIf Len(Me.id.Value & "") = 0 Then
MsgBox "You must enter a value into Patient Number."
Me.id.SetFocus
ElseIf Len(Me.ptin.Value & "") = 0 Then
MsgBox "You must enter a value into Patient Initials."
Me.ptin.SetFocus
ElseIf Len(Me.course.Value & "") = 0 Then
MsgBox "You must enter a value into Course."
Me.course.SetFocus
ElseIf Len(Me.data1_init.Value & "") = 0 Then
MsgBox "You must enter a value into Data Entry 1 Initials."
Me.data1_init.SetFocus
Else
DoCmd.RunCommand acCmdSaveRecord
DoCmd.GoToRecord acDataForm, "FCycUrinalysis", acNewRec
Call ClearControls(Me)
DoCmd.GoToControl "course"
End If
End Sub
--
Pat Dools
"Albert D.Kallal" wrote:
> > DoCmd.Save acForm, "FCycDoseVitalAmp"
>
> The above command actually saves the form, and not the data. Clearly, you
> don't need, nor want to save the form, so, dump the above line, it is NOT
> needed.
>
> > DoCmd.OpenForm "FCycDoseVitalAmp", acNormal
>
> Why are you opening the form when it is already open? Again, you don't need
> to open a form that is already open. So, dump the above line, it is NOT
> needed.
>
> > DoCmd.GoToRecord acDataForm, "FCycDoseVitalAmp", acNewRec
>
> The above looks fine. Remember, if your code, or your user navigates to
> another record, ms-access thoughtfully, and kindly saves the current data
> for you
>
> > DoCmd.GoToControl "course"
>
> The above is also fine. I tend to prefer using the setfocus method of a
> control., such as
>
> course.SetFocus
>
> I prefer the above since it implies that I am working with a control, and
> you also get inteli-sense as you type it. Further, if you miss type the
> name, and compile your code, you get a error. With the docmd, you only get
> the error at RUNTIME, and so the compiler can't check your syntax for you.
> As developer, you no doubt compile your code after any changes you make, and
> thus using methods of control are checked at compile time. (setfocus is a
> method of the control called course, and this is checked for you during
> compile time).
>
> --
> Albert D. Kallal (Access MVP)
> Edmonton, Alberta Canada
> pleaseNOOSpamKallal@xxxxxxx
> http://www.members.shaw.ca/AlbertKallal
>
>
>
.
- Follow-Ups:
- Re: Proper way to save a record
- From: Albert D.Kallal
- Re: Proper way to save a record
- References:
- Proper way to save a record
- From: Pat Dools
- Re: Proper way to save a record
- From: Albert D.Kallal
- Proper way to save a record
- Prev by Date: Re: set focus to last field in a subform (data*** view)
- Next by Date: Access & Citrix
- Previous by thread: Re: Proper way to save a record
- Next by thread: Re: Proper way to save a record
- Index(es):