Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

What is wrong with my code!

Discussion in 'Information Technology' started by Bob, Jul 28, 2006.

Tags:
  1. Bob

    Bob
    Expand Collapse
    Guest

    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
     
  2. Loading...


  3. Ken Snell \(MVP\)

    Ken Snell \(MVP\)
    Expand Collapse
    Guest

    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 Snell
    <MS ACCESS MVP>

    "Bob" <xxx@xx.xx> wrote in message news:e7kq7i$g9r$1@lust.ihug.co.nz...
    >
    >
    > 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
    >
     
  4. Bob

    Bob
    Expand Collapse
    Guest

    Thanks Ken for your HELP! worked perfect..Thanks Bob

    "Ken Snell (MVP)" <kthsneisllis9@ncoomcastt.renaetl> wrote in message
    news:esBk2CAmGHA.508@TK2MSFTNGP03.phx.gbl...
    > 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 Snell
    > <MS ACCESS MVP>
    >
    > "Bob" <xxx@xx.xx> wrote in message news:e7kq7i$g9r$1@lust.ihug.co.nz...
    >>
    >>
    >> 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
    >>

    >
    >
     
  5. Bob

    Bob
    Expand Collapse
    Guest

    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
    "Bob" <xxx@xx.xx> wrote in message news:e7l3lg$1tn$1@lust.ihug.co.nz...
    > Thanks Ken for your HELP! worked perfect..Thanks Bob
    >
    > "Ken Snell (MVP)" <kthsneisllis9@ncoomcastt.renaetl> wrote in message
    > news:esBk2CAmGHA.508@TK2MSFTNGP03.phx.gbl...
    >> 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 Snell
    >> <MS ACCESS MVP>
    >>
    >> "Bob" <xxx@xx.xx> wrote in message news:e7kq7i$g9r$1@lust.ihug.co.nz...
    >>>
    >>>
    >>> 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
    >>>

    >>
    >>

    >
    >
     
  6. Ken Snell \(MVP\)

    Ken Snell \(MVP\)
    Expand Collapse
    Guest

    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.
    --

    Ken Snell
    <MS ACCESS MVP>



    "Bob" <xxx@xx.xx> wrote in message news:e7l4dt$3e3$1@lust.ihug.co.nz...
    > 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
    > "Bob" <xxx@xx.xx> wrote in message news:e7l3lg$1tn$1@lust.ihug.co.nz...
    >> Thanks Ken for your HELP! worked perfect..Thanks Bob
    >>
    >> "Ken Snell (MVP)" <kthsneisllis9@ncoomcastt.renaetl> wrote in message
    >> news:esBk2CAmGHA.508@TK2MSFTNGP03.phx.gbl...
    >>> 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 Snell
    >>> <MS ACCESS MVP>
    >>>
    >>> "Bob" <xxx@xx.xx> wrote in message news:e7kq7i$g9r$1@lust.ihug.co.nz...
    >>>>
    >>>>
    >>>> 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
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
  7. Rick Brandt

    Rick Brandt
    Expand Collapse
    Guest

    "Bob" <xxx@xx.xx> wrote in message news:e7l4dt$3e3$1@lust.ihug.co.nz...
    > 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, Microsoft Access MVP
    Email (as appropriate) to...
    RBrandt at Hunter dot com
     
  8. Ken Snell \(MVP\)

    Ken Snell \(MVP\)
    Expand Collapse
    Guest

    "Rick Brandt" <rickbrandt2@hotmail.com> wrote in message
    news:V5vng.56382$Lm5.45914@newssvr12.news.prodigy.com...
    > "Bob" <xxx@xx.xx> wrote in message news:e7l4dt$3e3$1@lust.ihug.co.nz...
    >> 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.
    >


    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!).
    --

    Ken Snell
    <MS ACCESS MVP>
     

Share This Page