My code wont work Why?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Williams

    My code wont work Why?

    I have this code behind a command button but it doesn't delete the record.
    If vbNo = MsgBox("Are you sure you want to save this new record?", 4) Then
    DoCmd.DoMenuIte m acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuIte m acFormBar, acEditMenu, 6, , acMenuVer70
    If vbYes = MsgBox("Do you want to input another record?", 4) Then
    [DocNametxt].SetFocus
    End If
    DoCmd.Close

    I've also tried
    DoCmd.RunComman d acCmdDeleteReco rd
    But this didn't work either
    Anyone help me with why?
    TIA
    Tony Williams


  • Don Leverton

    #2
    Re: My code wont work Why?

    Hi Tony,

    I'm assuming that you're using Access97 or newer here, correct?
    I hate that Access95 DoMenuItem crap ... try using the form's "Dirty"
    property instead ... like this:

    If Msgbox("Are you sure you want to save this new record?", vbYesNo) =
    vbYes Then
    'If the user clicks Yes, this "saves" the current record
    Me.Dirty = False

    Else
    'If the user clicks No, this "un-does" the changes to the current
    record.
    Me.Undo

    'Now, "nest" your other "If" statement here ... so that this msg is only
    displayed if the user clicks No in the first msg.
    If MsgBox("Would you like to input something else?", vbYesNo) =
    vbYes Then
    Me.[DocNametxt].SetFocus
    Else
    DoCmd .Close
    End If

    End If


    --
    HTH,
    Don
    =============== ==============
    Use My.Name@Telus.N et for e-mail
    Disclaimer:
    Professional PartsPerson
    Amateur Database Programmer {:o)

    I'm an Access97 user, so all posted code
    samples are also Access97- based
    unless otherwise noted.
    =============== ==============

    "Tony Williams" <tw@tcp.invalid > wrote in message
    news:c4hh06$deo $2@hercules.bti nternet.com...[color=blue]
    > I have this code behind a command button but it doesn't delete the record.
    > If vbNo = MsgBox("Are you sure you want to save this new record?", 4) Then
    > DoCmd.DoMenuIte m acFormBar, acEditMenu, 8, , acMenuVer70
    > DoCmd.DoMenuIte m acFormBar, acEditMenu, 6, , acMenuVer70
    > If vbYes = MsgBox("Do you want to input another record?", 4) Then
    > [DocNametxt].SetFocus
    > End If
    > DoCmd.Close
    >
    > I've also tried
    > DoCmd.RunComman d acCmdDeleteReco rd
    > But this didn't work either
    > Anyone help me with why?
    > TIA
    > Tony Williams
    >
    >[/color]


    Comment

    • Tony Williams

      #3
      Re: My code wont work Why?

      Thanks Don works just fine I'm using A20000
      Tony
      "Don Leverton" <leveriteNoJunk Mail@telusplane t.net> wrote in message
      news:O%3bc.48$B 16.37@edtnps89. ..[color=blue]
      > Hi Tony,
      >
      > I'm assuming that you're using Access97 or newer here, correct?
      > I hate that Access95 DoMenuItem crap ... try using the form's "Dirty"
      > property instead ... like this:
      >
      > If Msgbox("Are you sure you want to save this new record?", vbYesNo) =
      > vbYes Then
      > 'If the user clicks Yes, this "saves" the current record
      > Me.Dirty = False
      >
      > Else
      > 'If the user clicks No, this "un-does" the changes to the current
      > record.
      > Me.Undo
      >
      > 'Now, "nest" your other "If" statement here ... so that this msg is[/color]
      only[color=blue]
      > displayed if the user clicks No in the first msg.
      > If MsgBox("Would you like to input something else?", vbYesNo) =
      > vbYes Then
      > Me.[DocNametxt].SetFocus
      > Else
      > DoCmd .Close
      > End If
      >
      > End If
      >
      >
      > --
      > HTH,
      > Don
      > =============== ==============
      > Use My.Name@Telus.N et for e-mail
      > Disclaimer:
      > Professional PartsPerson
      > Amateur Database Programmer {:o)
      >
      > I'm an Access97 user, so all posted code
      > samples are also Access97- based
      > unless otherwise noted.
      > =============== ==============
      >
      > "Tony Williams" <tw@tcp.invalid > wrote in message
      > news:c4hh06$deo $2@hercules.bti nternet.com...[color=green]
      > > I have this code behind a command button but it doesn't delete the[/color][/color]
      record.[color=blue][color=green]
      > > If vbNo = MsgBox("Are you sure you want to save this new record?", 4)[/color][/color]
      Then[color=blue][color=green]
      > > DoCmd.DoMenuIte m acFormBar, acEditMenu, 8, , acMenuVer70
      > > DoCmd.DoMenuIte m acFormBar, acEditMenu, 6, , acMenuVer70
      > > If vbYes = MsgBox("Do you want to input another record?", 4) Then
      > > [DocNametxt].SetFocus
      > > End If
      > > DoCmd.Close
      > >
      > > I've also tried
      > > DoCmd.RunComman d acCmdDeleteReco rd
      > > But this didn't work either
      > > Anyone help me with why?
      > > TIA
      > > Tony Williams
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...