What is wrong with my code!

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

This code is working fine in a earlier programme, but now it will not bring
up a new record, It goes to Horse records but only to record 1, I know it
does work as have it working earlier, maybe something that prevents it going
to new record:
Private Sub Command98_Click()
If MsgBox("Does this NEW Horse have it's Client in STABLEIZE? If NO go back
and enter it in Clients!", vbQuestion + vbYesNo) = vbNo Then


Exit Sub
End If
On Error GoTo Err_Command98_Click

DoCmd.OpenForm "frmHorseInfo"
DoCmd.GoToRecord , , acNewRec

Exit_Command98_Click:
Exit Sub

Err_Command98_Click:
MsgBox Err.Description
Resume Exit_Command98_Click


End Sub



Thanks in advance.........Bob Vance
 
Your code is moving the first form to a new record, not the frmHorseInfo
form to a new record. If you just want to add a new record via frmHorseInfo,
then change the DoCmd.OpenForm step to this and delete the DoCmd.GoToRecord
step:

DoCmd.OpenForm "frmHorseInfo", , , , acFormAdd
 
Ken is this one wrong as well. But it does work!
Private Sub Command68_Click()
On Error GoTo Err_Command68_Click
DoCmd.OpenForm "frmOwnerInfo"


DoCmd.GoToRecord , , acNewRec

Exit_Command68_Click:
Exit Sub

Err_Command68_Click:
MsgBox Err.Description
Resume Exit_Command68_Click


End Sub
 
Yes, it's wrong, but it would seem to work if the frmOwnerInfo has its Data
Entry property set to Yes (open that form in design ivew and open Properties
window to see). But this code will not cause a new record to be "moved to"
in frmOwnerInfo form when it opens.
 
Bob said:
Ken is this one wrong as well. But it does work!
Private Sub Command68_Click()
On Error GoTo Err_Command68_Click
DoCmd.OpenForm "frmOwnerInfo"


DoCmd.GoToRecord , , acNewRec

My understanding is that...

DoCmd.GoToRecord , , acNewRec

....is applied to whichever form has the focus. So this very well could be a
timing issue. A form that opens sufficiently fast might do what you want
because it has obtained focus when the go to record line of code runs.
 
Rick Brandt said:
My understanding is that...

DoCmd.GoToRecord , , acNewRec

...is applied to whichever form has the focus. So this very well could be
a timing issue. A form that opens sufficiently fast might do what you
want because it has obtained focus when the go to record line of code
runs.

Good point, Rick. This probably is similar to the issue of DoCmd.Close where
the object with the focus is the one that gets closed. ... I just checked
2003 Help, and surprisingly to me the Help file shows this example for how
to do what Bob requests:

< Help file excerpt start>
The following example opens a form in Form view and moves to a new record.
Sub ShowNewRecord()
DoCmd.OpenForm "Employees", acNormal
DoCmd.GoToRecord , , acNewRec
End Sub
<Help file excerpt end>

Bob, because focus is not always under one's control as one might wish,
using nonambiguous and nonerrorprone code steps is preferred when developing
programming (regardless of what the Help file says!).
 
Back
Top