Form Doesn't Go To New Record

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

    Form Doesn't Go To New Record

    I have a form with about 25 fields. In the BeforeUpdate event of the form, I
    have code that sets the default value of each field to its current value. For a
    new record, I can put the focus in any field to start. If I edit that field and
    then click on the new record button in the navigation buttons, the form goes to
    a new record and each field has the default value of the previous record. If I
    put the focus in any field to start, edit that field go to any other field and
    edit it, when I click on the new record button in the navigation buttons the
    form does not go to a new record. I have to click the new record button a second
    time to go to a new record. I also tried putting the code to set the defaults in
    the AfterUpdate event of the form and I get the same problem of having to click
    on the new record button twice.

    Does anyone have any thoughts as to what may be causing this behaviour?

    Thanks!

    Steve


  • Dirk Goldgar

    #2
    Re: Form Doesn't Go To New Record

    "Steve" <spam@nospam.sp am> wrote in message
    news:giVoc.8817 $KE6.4329@newsr ead3.news.atl.e arthlink.net[color=blue]
    > I have a form with about 25 fields. In the BeforeUpdate event of the
    > form, I have code that sets the default value of each field to its
    > current value. For a new record, I can put the focus in any field to
    > start. If I edit that field and then click on the new record button
    > in the navigation buttons, the form goes to a new record and each
    > field has the default value of the previous record. If I put the
    > focus in any field to start, edit that field go to any other field
    > and edit it, when I click on the new record button in the navigation
    > buttons the form does not go to a new record. I have to click the new
    > record button a second time to go to a new record. I also tried
    > putting the code to set the defaults in the AfterUpdate event of the
    > form and I get the same problem of having to click on the new record
    > button twice.
    >
    > Does anyone have any thoughts as to what may be causing this
    > behaviour?
    >
    > Thanks!
    >
    > Steve[/color]

    I think you'd better post the code behind the form.

    --
    Dirk Goldgar, MS Access MVP


    (please reply to the newsgroup)


    Comment

    • Steve

      #3
      Re: Form Doesn't Go To New Record

      Private Sub Form_BeforeUpda te(Cancel As Integer)
      Dim Ctrl As Control
      For Each Ctrl In Me.Controls
      If Ctrl.ControlTyp e <> acLabel And Ctrl.ControlTyp e <> acCommandButton Then
      If Not IsNull(Ctrl.Val ue) Then
      If InStr(Ctrl.Valu e, vbCrLf) > 0 Then
      MsgBox Ctrl.Controls(0 ).Caption & " Contains A Line Return." & vbCrLf &
      vbCrLf _
      & "The New Item Can Not Be Saved In The Database" & vbCrLf _
      & "Until The Line Return Is Removed." & vbCrLf & vbCrLf _
      & "Please Remove The Line Return!"
      Cancel = True
      Ctrl.SetFocus
      Exit Sub
      End If
      End If
      End If
      Next Ctrl

      ' BeforeUpdate Event Is Used For This So InvNumber = StoreItemID When The Item
      Is Saved
      Me!InvNumber = Me!StoreItemID
      If Me!SetThisItemA sTheDefaultNewI tem = True Then
      Call SetDefaultValue s
      Else
      Call RemoveDefaultVa lues
      End If
      Me!Title.SetFoc us
      End Sub

      Public Sub SetDefaultValue s()
      On Error GoTo ErrorHandler
      Me!Title.Defaul tValue = CQuote & Me!Title & CQuote
      Me!FeatureFlag. DefaultValue = CQuote & Me!FeatureFlag & CQuote
      Me!ShortDesc.De faultValue = CQuote & Me!ShortDesc & CQuote
      Me!Description. DefaultValue = CQuote & Me!Description & CQuote
      Me!ThumbImage.D efaultValue = CQuote & Me!ThumbImage & CQuote
      Me!FullImage.De faultValue = CQuote & Me!FullImage & CQuote

      If Not IsNull(Me!Categ ory) Then
      Me!Category.Def aultValue = CQuote & Me!Category & CQuote
      Else
      Me!Category.Def aultValue = ""
      End If
      If Not IsNull(Me!Secti on) Then
      Me!Section.Defa ultValue = CQuote & Me!Section & CQuote
      Else
      Me!Section.Defa ultValue = ""
      End If
      If Not IsNull(Me!Aisle ) Then
      Me!Aisle.Defaul tValue = CQuote & Me!Aisle & CQuote
      Else
      Me!Aisle.Defaul tValue = ""
      End If

      Me!Alt1.Default Value = CQuote & Me!Alt1 & CQuote
      Me!Alt2.Default Value = CQuote & Me!Alt2 & CQuote
      Me!Alt3.Default Value = CQuote & Me!Alt3 & CQuote
      Me!ListValue.De faultValue = CQuote & Me!ListValue & CQuote
      Me!SalePrice.De faultValue = CQuote & Me!SalePrice & CQuote
      Me!SellingPrice .DefaultValue = CQuote & Me!SellingPrice & CQuote
      Me!DatePurchase d.DefaultValue = CQuote & Me!DatePurchase d & CQuote
      Me!ItemCost.Def aultValue = CQuote & Me!ItemCost & CQuote
      Me!ShipCost.Def aultValue = CQuote & Me!ShipCost & CQuote

      If Not IsNull(Me!Inven toryLocation) Then
      Me!InventoryLoc ation.DefaultVa lue = CQuote & Me!InventoryLoc ation & CQuote
      Else
      Me!InventoryLoc ation.DefaultVa lue = ""
      End If

      Me!Inventory.De faultValue = CQuote & Me!Inventory & CQuote
      Me!ReorderPoint .DefaultValue = CQuote & Me!ReorderPoint & CQuote
      Me!Quantity.Def aultValue = CQuote & Me!Quantity & CQuote


      ExitHere:
      Me!Title.SetFoc us
      Exit Sub
      ErrorHandler:
      MsgBox Err.Description , , "Error# " & Err.Number
      Resume ExitHere
      End Sub

      Public Sub RemoveDefaultVa lues()
      Me!Title.Defaul tValue = ""
      Me!FeatureFlag. DefaultValue = ""
      Me!ShortDesc.De faultValue = ""
      Me!Description. DefaultValue = ""
      Me!ThumbImage.D efaultValue = ""
      Me!FullImage.De faultValue = ""
      Me!Category.Def aultValue = ""
      Me!Section.Defa ultValue = ""
      Me!Aisle.Defaul tValue = ""
      Me!Alt1.Default Value = ""
      Me!Alt2.Default Value = ""
      Me!Alt3.Default Value = ""
      Me!ListValue.De faultValue = ""
      Me!SalePrice.De faultValue = ""
      Me!SellingPrice .DefaultValue = ""
      Me!DatePurchase d.DefaultValue = ""
      Me!ItemCost.Def aultValue = ""
      Me!ShipCost.Def aultValue = ""
      Me!InventoryLoc ation.DefaultVa lue = ""
      Me!Inventory.De faultValue = ""
      Me!ReorderPoint .DefaultValue = ""
      Me!Quantity.Def aultValue = ""
      End Sub

      "Dirk Goldgar" <dg@NOdataSPAMg nostics.com> wrote in message
      news:OacIObVOEH A.3420@TK2MSFTN GP11.phx.gbl...[color=blue]
      > "Steve" <spam@nospam.sp am> wrote in message
      > news:giVoc.8817 $KE6.4329@newsr ead3.news.atl.e arthlink.net[color=green]
      > > I have a form with about 25 fields. In the BeforeUpdate event of the
      > > form, I have code that sets the default value of each field to its
      > > current value. For a new record, I can put the focus in any field to
      > > start. If I edit that field and then click on the new record button
      > > in the navigation buttons, the form goes to a new record and each
      > > field has the default value of the previous record. If I put the
      > > focus in any field to start, edit that field go to any other field
      > > and edit it, when I click on the new record button in the navigation
      > > buttons the form does not go to a new record. I have to click the new
      > > record button a second time to go to a new record. I also tried
      > > putting the code to set the defaults in the AfterUpdate event of the
      > > form and I get the same problem of having to click on the new record
      > > button twice.
      > >
      > > Does anyone have any thoughts as to what may be causing this
      > > behaviour?
      > >
      > > Thanks!
      > >
      > > Steve[/color]
      >
      > I think you'd better post the code behind the form.
      >
      > --
      > Dirk Goldgar, MS Access MVP
      > www.datagnostics.com
      >
      > (please reply to the newsgroup)
      >
      >[/color]


      Comment

      • Dirk Goldgar

        #4
        Re: Form Doesn't Go To New Record

        "Steve" <spam@nospam.sp am> wrote in message
        news:ks3pc.5478 $zO3.2582@newsr ead2.news.atl.e arthlink.net[color=blue]
        > Private Sub Form_BeforeUpda te(Cancel As Integer)
        > Dim Ctrl As Control
        > For Each Ctrl In Me.Controls
        > If Ctrl.ControlTyp e <> acLabel And Ctrl.ControlTyp e <>
        > acCommandButton Then If Not IsNull(Ctrl.Val ue) Then
        > If InStr(Ctrl.Valu e, vbCrLf) > 0 Then
        > MsgBox Ctrl.Controls(0 ).Caption & " Contains A Line Return."
        > & vbCrLf & vbCrLf _
        > & "The New Item Can Not Be Saved In The Database" & vbCrLf _
        > & "Until The Line Return Is Removed." & vbCrLf & vbCrLf _
        > & "Please Remove The Line Return!"
        > Cancel = True
        > Ctrl.SetFocus
        > Exit Sub
        > End If
        > End If
        > End If
        > Next Ctrl
        >
        > ' BeforeUpdate Event Is Used For This So InvNumber = StoreItemID When
        > The Item Is Saved
        > Me!InvNumber = Me!StoreItemID
        > If Me!SetThisItemA sTheDefaultNewI tem = True Then
        > Call SetDefaultValue s
        > Else
        > Call RemoveDefaultVa lues
        > End If
        > Me!Title.SetFoc us
        > End Sub
        >
        > Public Sub SetDefaultValue s()
        > On Error GoTo ErrorHandler
        > Me!Title.Defaul tValue = CQuote & Me!Title & CQuote
        > Me!FeatureFlag. DefaultValue = CQuote & Me!FeatureFlag & CQuote
        > Me!ShortDesc.De faultValue = CQuote & Me!ShortDesc & CQuote
        > Me!Description. DefaultValue = CQuote & Me!Description & CQuote
        > Me!ThumbImage.D efaultValue = CQuote & Me!ThumbImage & CQuote
        > Me!FullImage.De faultValue = CQuote & Me!FullImage & CQuote
        >
        > If Not IsNull(Me!Categ ory) Then
        > Me!Category.Def aultValue = CQuote & Me!Category & CQuote
        > Else
        > Me!Category.Def aultValue = ""
        > End If
        > If Not IsNull(Me!Secti on) Then
        > Me!Section.Defa ultValue = CQuote & Me!Section & CQuote
        > Else
        > Me!Section.Defa ultValue = ""
        > End If
        > If Not IsNull(Me!Aisle ) Then
        > Me!Aisle.Defaul tValue = CQuote & Me!Aisle & CQuote
        > Else
        > Me!Aisle.Defaul tValue = ""
        > End If
        >
        > Me!Alt1.Default Value = CQuote & Me!Alt1 & CQuote
        > Me!Alt2.Default Value = CQuote & Me!Alt2 & CQuote
        > Me!Alt3.Default Value = CQuote & Me!Alt3 & CQuote
        > Me!ListValue.De faultValue = CQuote & Me!ListValue & CQuote
        > Me!SalePrice.De faultValue = CQuote & Me!SalePrice & CQuote
        > Me!SellingPrice .DefaultValue = CQuote & Me!SellingPrice & CQuote
        > Me!DatePurchase d.DefaultValue = CQuote & Me!DatePurchase d & CQuote
        > Me!ItemCost.Def aultValue = CQuote & Me!ItemCost & CQuote
        > Me!ShipCost.Def aultValue = CQuote & Me!ShipCost & CQuote
        >
        > If Not IsNull(Me!Inven toryLocation) Then
        > Me!InventoryLoc ation.DefaultVa lue = CQuote & Me!InventoryLoc ation &
        > CQuote Else
        > Me!InventoryLoc ation.DefaultVa lue = ""
        > End If
        >
        > Me!Inventory.De faultValue = CQuote & Me!Inventory & CQuote
        > Me!ReorderPoint .DefaultValue = CQuote & Me!ReorderPoint & CQuote
        > Me!Quantity.Def aultValue = CQuote & Me!Quantity & CQuote
        >
        >
        > ExitHere:
        > Me!Title.SetFoc us
        > Exit Sub
        > ErrorHandler:
        > MsgBox Err.Description , , "Error# " & Err.Number
        > Resume ExitHere
        > End Sub
        >
        > Public Sub RemoveDefaultVa lues()
        > Me!Title.Defaul tValue = ""
        > Me!FeatureFlag. DefaultValue = ""
        > Me!ShortDesc.De faultValue = ""
        > Me!Description. DefaultValue = ""
        > Me!ThumbImage.D efaultValue = ""
        > Me!FullImage.De faultValue = ""
        > Me!Category.Def aultValue = ""
        > Me!Section.Defa ultValue = ""
        > Me!Aisle.Defaul tValue = ""
        > Me!Alt1.Default Value = ""
        > Me!Alt2.Default Value = ""
        > Me!Alt3.Default Value = ""
        > Me!ListValue.De faultValue = ""
        > Me!SalePrice.De faultValue = ""
        > Me!SellingPrice .DefaultValue = ""
        > Me!DatePurchase d.DefaultValue = ""
        > Me!ItemCost.Def aultValue = ""
        > Me!ShipCost.Def aultValue = ""
        > Me!InventoryLoc ation.DefaultVa lue = ""
        > Me!Inventory.De faultValue = ""
        > Me!ReorderPoint .DefaultValue = ""
        > Me!Quantity.Def aultValue = ""
        > End Sub
        >
        > "Dirk Goldgar" <dg@NOdataSPAMg nostics.com> wrote in message
        > news:OacIObVOEH A.3420@TK2MSFTN GP11.phx.gbl...[color=green]
        >> "Steve" <spam@nospam.sp am> wrote in message
        >> news:giVoc.8817 $KE6.4329@newsr ead3.news.atl.e arthlink.net[color=darkred]
        >>> I have a form with about 25 fields. In the BeforeUpdate event of the
        >>> form, I have code that sets the default value of each field to its
        >>> current value. For a new record, I can put the focus in any field to
        >>> start. If I edit that field and then click on the new record button
        >>> in the navigation buttons, the form goes to a new record and each
        >>> field has the default value of the previous record. If I put the
        >>> focus in any field to start, edit that field go to any other field
        >>> and edit it, when I click on the new record button in the navigation
        >>> buttons the form does not go to a new record. I have to click the
        >>> new record button a second time to go to a new record. I also tried
        >>> putting the code to set the defaults in the AfterUpdate event of the
        >>> form and I get the same problem of having to click on the new record
        >>> button twice.
        >>>
        >>> Does anyone have any thoughts as to what may be causing this
        >>> behaviour?
        >>>
        >>> Thanks!
        >>>
        >>> Steve[/color]
        >>
        >> I think you'd better post the code behind the form.[/color][/color]

        I have to say it's not obvious. Let me verify a couple of things.

        Is the "new record" button you're clicking one of the standard
        navigation buttons provided by having the form's NavigationButto ns
        property set to Yes?

        As I interpret your description of the problem, you are contrasting two
        behaviors, identified as A and B below:

        (A) Open Form. Go to new record. Edit the data in a control. Click
        "new record" button. Form goes to a new record.

        (B) Open Form. Go to new record. Edit the data in a control. Edit the
        data in another control. Click "new record" button. Form does *not* go
        to a new record, but stays on the current record. If you click the
        button again, *then* the form goes to a new record.

        Do the above statements correctly decribe what you are doing and seeing?
        Please verify exactly what it takes to get the dfferent behaviors,
        starting with a fresh opening of the form each time. Are you sure it
        doesn't matter what controls you edit?

        I notice that your code that loops through the controls excludes only
        labels and command buttons. There could conceivably be other types of
        controls that don't have a Value property -- lines, boxes, and such.
        Are you sure you don't have a problem there? You don't have error
        trapping turned off, do you? You have no error-handling in the
        Form_BeforeUpda te procedure.

        --
        Dirk Goldgar, MS Access MVP


        (please reply to the newsgroup)


        Comment

        • Bruce

          #5
          Re: Form Doesn't Go To New Record

          "Steve" <spam@nospam.sp am> wrote in message news:<ks3pc.547 8$zO3.2582@news read2.news.atl. earthlink.net>. ..[color=blue]
          > Private Sub Form_BeforeUpda te(Cancel As Integer)
          > Dim Ctrl As Control
          > For Each Ctrl In Me.Controls
          > If Ctrl.ControlTyp e <> acLabel And Ctrl.ControlTyp e <> acCommandButton Then
          > If Not IsNull(Ctrl.Val ue) Then
          > If InStr(Ctrl.Valu e, vbCrLf) > 0 Then
          > MsgBox Ctrl.Controls(0 ).Caption & " Contains A Line Return." & vbCrLf &
          > vbCrLf _
          > & "The New Item Can Not Be Saved In The Database" & vbCrLf _
          > & "Until The Line Return Is Removed." & vbCrLf & vbCrLf _
          > & "Please Remove The Line Return!"
          > Cancel = True
          > Ctrl.SetFocus
          > Exit Sub
          > End If
          > End If
          > End If
          > Next Ctrl
          >
          > ' BeforeUpdate Event Is Used For This So InvNumber = StoreItemID When The Item
          > Is Saved
          > Me!InvNumber = Me!StoreItemID
          > If Me!SetThisItemA sTheDefaultNewI tem = True Then
          > Call SetDefaultValue s
          > Else
          > Call RemoveDefaultVa lues
          > End If
          > Me!Title.SetFoc us
          > End Sub
          >
          > Public Sub SetDefaultValue s()
          > On Error GoTo ErrorHandler
          > Me!Title.Defaul tValue = CQuote & Me!Title & CQuote
          > Me!FeatureFlag. DefaultValue = CQuote & Me!FeatureFlag & CQuote
          > Me!ShortDesc.De faultValue = CQuote & Me!ShortDesc & CQuote
          > Me!Description. DefaultValue = CQuote & Me!Description & CQuote
          > Me!ThumbImage.D efaultValue = CQuote & Me!ThumbImage & CQuote
          > Me!FullImage.De faultValue = CQuote & Me!FullImage & CQuote
          >
          > If Not IsNull(Me!Categ ory) Then
          > Me!Category.Def aultValue = CQuote & Me!Category & CQuote
          > Else
          > Me!Category.Def aultValue = ""
          > End If
          > If Not IsNull(Me!Secti on) Then
          > Me!Section.Defa ultValue = CQuote & Me!Section & CQuote
          > Else
          > Me!Section.Defa ultValue = ""
          > End If
          > If Not IsNull(Me!Aisle ) Then
          > Me!Aisle.Defaul tValue = CQuote & Me!Aisle & CQuote
          > Else
          > Me!Aisle.Defaul tValue = ""
          > End If
          >
          > Me!Alt1.Default Value = CQuote & Me!Alt1 & CQuote
          > Me!Alt2.Default Value = CQuote & Me!Alt2 & CQuote
          > Me!Alt3.Default Value = CQuote & Me!Alt3 & CQuote
          > Me!ListValue.De faultValue = CQuote & Me!ListValue & CQuote
          > Me!SalePrice.De faultValue = CQuote & Me!SalePrice & CQuote
          > Me!SellingPrice .DefaultValue = CQuote & Me!SellingPrice & CQuote
          > Me!DatePurchase d.DefaultValue = CQuote & Me!DatePurchase d & CQuote
          > Me!ItemCost.Def aultValue = CQuote & Me!ItemCost & CQuote
          > Me!ShipCost.Def aultValue = CQuote & Me!ShipCost & CQuote
          >
          > If Not IsNull(Me!Inven toryLocation) Then
          > Me!InventoryLoc ation.DefaultVa lue = CQuote & Me!InventoryLoc ation & CQuote
          > Else
          > Me!InventoryLoc ation.DefaultVa lue = ""
          > End If
          >
          > Me!Inventory.De faultValue = CQuote & Me!Inventory & CQuote
          > Me!ReorderPoint .DefaultValue = CQuote & Me!ReorderPoint & CQuote
          > Me!Quantity.Def aultValue = CQuote & Me!Quantity & CQuote
          >
          >
          > ExitHere:
          > Me!Title.SetFoc us
          > Exit Sub
          > ErrorHandler:
          > MsgBox Err.Description , , "Error# " & Err.Number
          > Resume ExitHere
          > End Sub
          >
          > Public Sub RemoveDefaultVa lues()
          > Me!Title.Defaul tValue = ""
          > Me!FeatureFlag. DefaultValue = ""
          > Me!ShortDesc.De faultValue = ""
          > Me!Description. DefaultValue = ""
          > Me!ThumbImage.D efaultValue = ""
          > Me!FullImage.De faultValue = ""
          > Me!Category.Def aultValue = ""
          > Me!Section.Defa ultValue = ""
          > Me!Aisle.Defaul tValue = ""
          > Me!Alt1.Default Value = ""
          > Me!Alt2.Default Value = ""
          > Me!Alt3.Default Value = ""
          > Me!ListValue.De faultValue = ""
          > Me!SalePrice.De faultValue = ""
          > Me!SellingPrice .DefaultValue = ""
          > Me!DatePurchase d.DefaultValue = ""
          > Me!ItemCost.Def aultValue = ""
          > Me!ShipCost.Def aultValue = ""
          > Me!InventoryLoc ation.DefaultVa lue = ""
          > Me!Inventory.De faultValue = ""
          > Me!ReorderPoint .DefaultValue = ""
          > Me!Quantity.Def aultValue = ""
          > End Sub[/color]

          I think I would use a somewhat different approach here. Let the form
          save the record. In the AfterUpdate proc of the form, save whatever
          key value or values you need to be able to retrieve the record that
          you just saved. For example, if your key value is StoreItemID and
          that's a long integer, do something like:

          dim lngPrevItemID as long ' Do this in the (General) (Declarations)
          section of the form so it will be available to all procs in the form

          Form_AfterUpdat e()

          lngPrevItemID = Me.StoreItemID

          End Sub

          Then in the form's Current event, check to see if you're on a new
          record. If so, use the key value you just stored to look up the
          previously saved record and load in all the default values. For
          example, do something like the following in Form_Current():

          Dim rst As Recordset

          If Me.NewRecord Then
          Set rst = CurrentDB.OpenR ecordset("selec t * from MyTable where
          StoreItemID = " & lngPrevItemID
          Me!Field1.Defau ltValue = rst!Field1
          ...
          Me!Fieldn.Defau ltValue = rst!Fieldn
          rst.Close
          Set rst = Nothing
          Else
          Me!Field1.Defau ltValue = ""
          ...
          Me!Fieldn.Defau ltValue = ""
          End If

          -or-

          Dim rst As Recordset

          If Me.NewRecord Then
          Set rst = Me.RecordSetClo ne
          rst.FindFirst "StoreItemI D = " & lngPrevItemID
          Me!Field1.Defau ltValue = rst!Field1
          ...
          Me!Fieldn.Defau ltValue = rst!Fieldn
          rst.Close
          Set rst = Nothing
          Else
          Me!Field1.Defau ltValue = ""
          ...
          Me!Fieldn.Defau ltValue = ""
          End If

          You might be able to do this with bookmarks as well.

          Hope this helps.

          Bruce

          Comment

          • PC Datasheet

            #6
            Re: Form Doesn't Go To New Record

            Dirk,

            Thanks for the follow-up!!
            [color=blue]
            > Is the "new record" button you're clicking one of the standard
            > navigation buttons provided by having the form's NavigationButto ns
            > property set to Yes?[/color]

            *** Yes, the button with the astrisk at the far right. ***
            [color=blue]
            >
            > As I interpret your description of the problem, you are contrasting two
            > behaviors, identified as A and B below:
            >
            > (A) Open Form. Go to new record. Edit the data in a control. Click
            > "new record" button. Form goes to a new record.
            >
            > (B) Open Form. Go to new record. Edit the data in a control. Edit the
            > data in another control. Click "new record" button. Form does *not* go
            > to a new record, but stays on the current record. If you click the
            > button again, *then* the form goes to a new record.
            >
            > Do the above statements correctly decribe what you are doing and seeing?[/color]

            *** SetThisItemAsTh eDefaultNewItem is an option button on the form and is
            refeered to in the BeforeUpdate code. True calls the Public Sub
            SetDefaultValue s() and False calls the Public Sub RemoveDefaultVa lues(). I get
            the same behaviour whether the option button is set to True or False. The
            behaviour occurs on the first record as well as all subsequent records. When the
            form opens focus is on the first field in the tab order (Title). If I make an
            entry in that field and click on the New Record button, the form goes to a new
            record. If I tab or use the mouse to move the cursor to any other field and make
            an entry only in that field and then click the New Record button, the cursor
            jumps to the first field in the tab order but the form does not go to a new
            record. I have to click the New Record button again. The same thing happens on
            all subsequent new records.

            Note that at the end of the Public Sub SetDefaultValue s() code, focus is set for
            the field 'Title'. If I change the code to set focus on another field, I get the
            same behaviour. If I edit only the field that got the focus, one click goes to a
            new record. But if I tab or use the mouse to go to any other field, it takes two
            clicks to go to a new record. Public Sub RemoveDefaultVa lues() as is does not
            set the focus after running so focus goes to the first field in the tab order.
            And again I get the same behaviour. If I change the tab order, I get the same
            behaviour. I tried adding code in the Public Sub RemoveDefaultVa lues() to set
            focus to a particular field and get the same behaviour. ***

            [color=blue]
            > Please verify exactly what it takes to get the dfferent behaviors,
            > starting with a fresh opening of the form each time. Are you sure it
            > doesn't matter what controls you edit?
            >
            > I notice that your code that loops through the controls excludes only
            > labels and command buttons. There could conceivably be other types of
            > controls that don't have a Value property -- lines, boxes, and such.
            > Are you sure you don't have a problem there? You don't have error
            > trapping turned off, do you? You have no error-handling in the
            > Form_BeforeUpda te procedure.[/color]

            *** The purpose of the code at the beginning is to look for line returns in the
            data entry fields. The data entered on the form is saved to the database and
            also exported to a MySQL webstore. The webstore can not correctly process the
            data if it contains line returns when it imports the data. In regards to
            error-handling, I have not raised any errors in the various ways I have tried to
            make this work.

            The database and the webstore interface have worked flawlessly for several
            months. The form being discussed is for adding new items to the database and to
            the webstore. Sometimes a series of new items is added where most of the fields
            are the same for each item. Rather than typing in the same information for each
            item, I'm trying to set up a way to duplicate the previous item and then edit
            the few fields that need changed. I'm trying to do it through the default value
            of all the fields to avoid creating duplicate item records. ***

            "Dirk Goldgar" <dg@NOdataSPAMg nostics.com> wrote in message
            news:eQjKsfdOEH A.2976@TK2MSFTN GP10.phx.gbl...[color=blue]
            > "Steve" <spam@nospam.sp am> wrote in message
            > news:ks3pc.5478 $zO3.2582@newsr ead2.news.atl.e arthlink.net[color=green]
            > > Private Sub Form_BeforeUpda te(Cancel As Integer)
            > > Dim Ctrl As Control
            > > For Each Ctrl In Me.Controls
            > > If Ctrl.ControlTyp e <> acLabel And Ctrl.ControlTyp e <>
            > > acCommandButton Then If Not IsNull(Ctrl.Val ue) Then
            > > If InStr(Ctrl.Valu e, vbCrLf) > 0 Then
            > > MsgBox Ctrl.Controls(0 ).Caption & " Contains A Line Return."
            > > & vbCrLf & vbCrLf _
            > > & "The New Item Can Not Be Saved In The Database" & vbCrLf _
            > > & "Until The Line Return Is Removed." & vbCrLf & vbCrLf _
            > > & "Please Remove The Line Return!"
            > > Cancel = True
            > > Ctrl.SetFocus
            > > Exit Sub
            > > End If
            > > End If
            > > End If
            > > Next Ctrl
            > >
            > > ' BeforeUpdate Event Is Used For This So InvNumber = StoreItemID When
            > > The Item Is Saved
            > > Me!InvNumber = Me!StoreItemID
            > > If Me!SetThisItemA sTheDefaultNewI tem = True Then
            > > Call SetDefaultValue s
            > > Else
            > > Call RemoveDefaultVa lues
            > > End If
            > > Me!Title.SetFoc us
            > > End Sub
            > >
            > > Public Sub SetDefaultValue s()
            > > On Error GoTo ErrorHandler
            > > Me!Title.Defaul tValue = CQuote & Me!Title & CQuote
            > > Me!FeatureFlag. DefaultValue = CQuote & Me!FeatureFlag & CQuote
            > > Me!ShortDesc.De faultValue = CQuote & Me!ShortDesc & CQuote
            > > Me!Description. DefaultValue = CQuote & Me!Description & CQuote
            > > Me!ThumbImage.D efaultValue = CQuote & Me!ThumbImage & CQuote
            > > Me!FullImage.De faultValue = CQuote & Me!FullImage & CQuote
            > >
            > > If Not IsNull(Me!Categ ory) Then
            > > Me!Category.Def aultValue = CQuote & Me!Category & CQuote
            > > Else
            > > Me!Category.Def aultValue = ""
            > > End If
            > > If Not IsNull(Me!Secti on) Then
            > > Me!Section.Defa ultValue = CQuote & Me!Section & CQuote
            > > Else
            > > Me!Section.Defa ultValue = ""
            > > End If
            > > If Not IsNull(Me!Aisle ) Then
            > > Me!Aisle.Defaul tValue = CQuote & Me!Aisle & CQuote
            > > Else
            > > Me!Aisle.Defaul tValue = ""
            > > End If
            > >
            > > Me!Alt1.Default Value = CQuote & Me!Alt1 & CQuote
            > > Me!Alt2.Default Value = CQuote & Me!Alt2 & CQuote
            > > Me!Alt3.Default Value = CQuote & Me!Alt3 & CQuote
            > > Me!ListValue.De faultValue = CQuote & Me!ListValue & CQuote
            > > Me!SalePrice.De faultValue = CQuote & Me!SalePrice & CQuote
            > > Me!SellingPrice .DefaultValue = CQuote & Me!SellingPrice & CQuote
            > > Me!DatePurchase d.DefaultValue = CQuote & Me!DatePurchase d & CQuote
            > > Me!ItemCost.Def aultValue = CQuote & Me!ItemCost & CQuote
            > > Me!ShipCost.Def aultValue = CQuote & Me!ShipCost & CQuote
            > >
            > > If Not IsNull(Me!Inven toryLocation) Then
            > > Me!InventoryLoc ation.DefaultVa lue = CQuote & Me!InventoryLoc ation &
            > > CQuote Else
            > > Me!InventoryLoc ation.DefaultVa lue = ""
            > > End If
            > >
            > > Me!Inventory.De faultValue = CQuote & Me!Inventory & CQuote
            > > Me!ReorderPoint .DefaultValue = CQuote & Me!ReorderPoint & CQuote
            > > Me!Quantity.Def aultValue = CQuote & Me!Quantity & CQuote
            > >
            > >
            > > ExitHere:
            > > Me!Title.SetFoc us
            > > Exit Sub
            > > ErrorHandler:
            > > MsgBox Err.Description , , "Error# " & Err.Number
            > > Resume ExitHere
            > > End Sub
            > >
            > > Public Sub RemoveDefaultVa lues()
            > > Me!Title.Defaul tValue = ""
            > > Me!FeatureFlag. DefaultValue = ""
            > > Me!ShortDesc.De faultValue = ""
            > > Me!Description. DefaultValue = ""
            > > Me!ThumbImage.D efaultValue = ""
            > > Me!FullImage.De faultValue = ""
            > > Me!Category.Def aultValue = ""
            > > Me!Section.Defa ultValue = ""
            > > Me!Aisle.Defaul tValue = ""
            > > Me!Alt1.Default Value = ""
            > > Me!Alt2.Default Value = ""
            > > Me!Alt3.Default Value = ""
            > > Me!ListValue.De faultValue = ""
            > > Me!SalePrice.De faultValue = ""
            > > Me!SellingPrice .DefaultValue = ""
            > > Me!DatePurchase d.DefaultValue = ""
            > > Me!ItemCost.Def aultValue = ""
            > > Me!ShipCost.Def aultValue = ""
            > > Me!InventoryLoc ation.DefaultVa lue = ""
            > > Me!Inventory.De faultValue = ""
            > > Me!ReorderPoint .DefaultValue = ""
            > > Me!Quantity.Def aultValue = ""
            > > End Sub
            > >
            > > "Dirk Goldgar" <dg@NOdataSPAMg nostics.com> wrote in message
            > > news:OacIObVOEH A.3420@TK2MSFTN GP11.phx.gbl...[color=darkred]
            > >> "Steve" <spam@nospam.sp am> wrote in message
            > >> news:giVoc.8817 $KE6.4329@newsr ead3.news.atl.e arthlink.net
            > >>> I have a form with about 25 fields. In the BeforeUpdate event of the
            > >>> form, I have code that sets the default value of each field to its
            > >>> current value. For a new record, I can put the focus in any field to
            > >>> start. If I edit that field and then click on the new record button
            > >>> in the navigation buttons, the form goes to a new record and each
            > >>> field has the default value of the previous record. If I put the
            > >>> focus in any field to start, edit that field go to any other field
            > >>> and edit it, when I click on the new record button in the navigation
            > >>> buttons the form does not go to a new record. I have to click the
            > >>> new record button a second time to go to a new record. I also tried
            > >>> putting the code to set the defaults in the AfterUpdate event of the
            > >>> form and I get the same problem of having to click on the new record
            > >>> button twice.
            > >>>
            > >>> Does anyone have any thoughts as to what may be causing this
            > >>> behaviour?
            > >>>
            > >>> Thanks!
            > >>>
            > >>> Steve
            > >>
            > >> I think you'd better post the code behind the form.[/color][/color]
            >
            > I have to say it's not obvious. Let me verify a couple of things.
            >
            > Is the "new record" button you're clicking one of the standard
            > navigation buttons provided by having the form's NavigationButto ns
            > property set to Yes?
            >
            > As I interpret your description of the problem, you are contrasting two
            > behaviors, identified as A and B below:
            >
            > (A) Open Form. Go to new record. Edit the data in a control. Click
            > "new record" button. Form goes to a new record.
            >
            > (B) Open Form. Go to new record. Edit the data in a control. Edit the
            > data in another control. Click "new record" button. Form does *not* go
            > to a new record, but stays on the current record. If you click the
            > button again, *then* the form goes to a new record.
            >
            > Do the above statements correctly decribe what you are doing and seeing?
            > Please verify exactly what it takes to get the dfferent behaviors,
            > starting with a fresh opening of the form each time. Are you sure it
            > doesn't matter what controls you edit?
            >
            > I notice that your code that loops through the controls excludes only
            > labels and command buttons. There could conceivably be other types of
            > controls that don't have a Value property -- lines, boxes, and such.
            > Are you sure you don't have a problem there? You don't have error
            > trapping turned off, do you? You have no error-handling in the
            > Form_BeforeUpda te procedure.
            >
            > --
            > Dirk Goldgar, MS Access MVP
            > www.datagnostics.com
            >
            > (please reply to the newsgroup)
            >
            >[/color]



            Comment

            • rkc

              #7
              Re: Form Doesn't Go To New Record


              "Bruce" <bruce@aristotl e.net> wrote in message
              news:d3b3c84d.0 405141136.4c39c 7b8@posting.goo gle.com...[color=blue]
              > I think I would use a somewhat different approach here. Let the form
              > save the record. In the AfterUpdate proc of the form, save whatever
              > key value or values you need to be able to retrieve the record that
              > you just saved. For example, if your key value is StoreItemID and
              > that's a long integer, do something like:
              >
              > dim lngPrevItemID as long ' Do this in the (General) (Declarations)
              > section of the form so it will be available to all procs in the form
              >
              > Form_AfterUpdat e()
              >
              > lngPrevItemID = Me.StoreItemID
              >
              > End Sub
              >
              > Then in the form's Current event, check to see if you're on a new
              > record. If so, use the key value you just stored to look up the
              > previously saved record and load in all the default values. For
              > example, do something like the following in Form_Current():
              >
              > Dim rst As Recordset
              >
              > If Me.NewRecord Then
              > Set rst = CurrentDB.OpenR ecordset("selec t * from MyTable where
              > StoreItemID = " & lngPrevItemID
              > Me!Field1.Defau ltValue = rst!Field1
              > ...
              > Me!Fieldn.Defau ltValue = rst!Fieldn
              > rst.Close
              > Set rst = Nothing
              > Else
              > Me!Field1.Defau ltValue = ""
              > ...
              > Me!Fieldn.Defau ltValue = ""
              > End If
              >
              > -or-
              >
              > Dim rst As Recordset
              >
              > If Me.NewRecord Then
              > Set rst = Me.RecordSetClo ne
              > rst.FindFirst "StoreItemI D = " & lngPrevItemID
              > Me!Field1.Defau ltValue = rst!Field1
              > ...
              > Me!Fieldn.Defau ltValue = rst!Fieldn
              > rst.Close
              > Set rst = Nothing
              > Else
              > Me!Field1.Defau ltValue = ""
              > ...
              > Me!Fieldn.Defau ltValue = ""
              > End If[/color]

              My first thought would be to write a class that extends a textbox to
              include the behaviour that is wanted. You could handle both the
              setting of a defaultvalue and the removal of CRLF's.

              Something like:

              <class>
              Option Compare Database
              Option Explicit

              Private WithEvents frm As Access.Form
              Private txtbox As Access.TextBox

              Public Sub Init(tb As Access.TextBox)
              Set frm = tb.parent
              Set txtbox = tb
              frm.BeforeUpdat e = "[Event Procedure]"
              End Sub

              Private Sub frm_BeforeUpdat e(Cancel As Integer)
              If Len(txtbox.Valu e & vbNullString) > 0 Then
              txtbox.Value = Replace(txtbox. Value, vbCrLf, " ")
              txtbox.DefaultV alue = Chr$(34) & txtbox.Value & Chr$(34)
              End If
              End Sub

              Private Sub Class_Terminate ()
              If Not txtbox Is Nothing Then Set txtbox = Nothing
              If Not frm Is Nothing Then Set frm = Nothing
              End Sub
              </class>

              Set and load all the textboxes you want to have the behaviour
              into a collection in the form's open event.


              Comment

              • Steve

                #8
                Re: Form Doesn't Go To New Record

                RKC,

                Thanks for responding!

                To try and learn something new and understand what you propose, I have some
                questions:
                1. What is the advantage to what you propose?

                2. Where specifically does your code go?

                3. <<Set and load all the textboxes you want to have the behaviour into a
                collection in the form's open event.>> How do you do this? There around 25
                fields on the form, would you then cycle through the collection in the
                BeforeUpdate event code?

                4. There are a couple of memo fields, how are they handled?

                5. << txtbox.Value = Replace(txtbox. Value, vbCrLf, " ")>> Why are you replacing
                a CrLf with a space rather than a null string?

                6. What causes Private Sub Class_Terminate () to execute?

                Thank you very much for your help!

                Steve



                "rkc" <rkc@yabba.dabb a.do.rochester. rr.bomb> wrote in message
                news:jRgpc.3645 6$hY.25207@twis ter.nyroc.rr.co m...[color=blue]
                >
                > "Bruce" <bruce@aristotl e.net> wrote in message
                > news:d3b3c84d.0 405141136.4c39c 7b8@posting.goo gle.com...[color=green]
                > > I think I would use a somewhat different approach here. Let the form
                > > save the record. In the AfterUpdate proc of the form, save whatever
                > > key value or values you need to be able to retrieve the record that
                > > you just saved. For example, if your key value is StoreItemID and
                > > that's a long integer, do something like:
                > >
                > > dim lngPrevItemID as long ' Do this in the (General) (Declarations)
                > > section of the form so it will be available to all procs in the form
                > >
                > > Form_AfterUpdat e()
                > >
                > > lngPrevItemID = Me.StoreItemID
                > >
                > > End Sub
                > >
                > > Then in the form's Current event, check to see if you're on a new
                > > record. If so, use the key value you just stored to look up the
                > > previously saved record and load in all the default values. For
                > > example, do something like the following in Form_Current():
                > >
                > > Dim rst As Recordset
                > >
                > > If Me.NewRecord Then
                > > Set rst = CurrentDB.OpenR ecordset("selec t * from MyTable where
                > > StoreItemID = " & lngPrevItemID
                > > Me!Field1.Defau ltValue = rst!Field1
                > > ...
                > > Me!Fieldn.Defau ltValue = rst!Fieldn
                > > rst.Close
                > > Set rst = Nothing
                > > Else
                > > Me!Field1.Defau ltValue = ""
                > > ...
                > > Me!Fieldn.Defau ltValue = ""
                > > End If
                > >
                > > -or-
                > >
                > > Dim rst As Recordset
                > >
                > > If Me.NewRecord Then
                > > Set rst = Me.RecordSetClo ne
                > > rst.FindFirst "StoreItemI D = " & lngPrevItemID
                > > Me!Field1.Defau ltValue = rst!Field1
                > > ...
                > > Me!Fieldn.Defau ltValue = rst!Fieldn
                > > rst.Close
                > > Set rst = Nothing
                > > Else
                > > Me!Field1.Defau ltValue = ""
                > > ...
                > > Me!Fieldn.Defau ltValue = ""
                > > End If[/color]
                >
                > My first thought would be to write a class that extends a textbox to
                > include the behaviour that is wanted. You could handle both the
                > setting of a defaultvalue and the removal of CRLF's.
                >
                > Something like:
                >
                > <class>
                > Option Compare Database
                > Option Explicit
                >
                > Private WithEvents frm As Access.Form
                > Private txtbox As Access.TextBox
                >
                > Public Sub Init(tb As Access.TextBox)
                > Set frm = tb.parent
                > Set txtbox = tb
                > frm.BeforeUpdat e = "[Event Procedure]"
                > End Sub
                >
                > Private Sub frm_BeforeUpdat e(Cancel As Integer)
                > If Len(txtbox.Valu e & vbNullString) > 0 Then
                > txtbox.Value = Replace(txtbox. Value, vbCrLf, " ")
                > txtbox.DefaultV alue = Chr$(34) & txtbox.Value & Chr$(34)
                > End If
                > End Sub
                >
                > Private Sub Class_Terminate ()
                > If Not txtbox Is Nothing Then Set txtbox = Nothing
                > If Not frm Is Nothing Then Set frm = Nothing
                > End Sub
                > </class>
                >
                > Set and load all the textboxes you want to have the behaviour
                > into a collection in the form's open event.
                >
                >[/color]


                Comment

                • rkc

                  #9
                  Re: Form Doesn't Go To New Record


                  "Steve" <spam@nospam.sp am> wrote in message
                  news:2yppc.7041 $zO3.3581@newsr ead2.news.atl.e arthlink.net...

                  [color=blue]
                  > To try and learn something new and understand what you propose, I have[/color]
                  some[color=blue]
                  > questions:
                  > 1. What is the advantage to what you propose?[/color]

                  The code for the textbox(s) behaviour is all in one place, in a
                  class module.
                  [color=blue]
                  > 2. Where specifically does your code go?[/color]

                  The code between <class> and </class> goes in a new class module.
                  [color=blue]
                  > 3. <<Set and load all the textboxes you want to have the behaviour into[/color]
                  a[color=blue]
                  > collection in the form's open event.>> How do you do this? There around[/color]
                  25[color=blue]
                  > fields on the form, would you then cycle through the collection in the
                  > BeforeUpdate event code?[/color]


                  [color=blue]
                  > 4. There are a couple of memo fields, how are they handled?[/color]

                  Same as text fields

                  [color=blue]
                  > 5. << txtbox.Value = Replace(txtbox. Value, vbCrLf, " ")>> Why are you[/color]
                  replacing[color=blue]
                  > a CrLf with a space rather than a null string?[/color]

                  Because you can end up with two words run together if you don't.
                  [color=blue]
                  > 6. What causes Private Sub Class_Terminate () to execute?[/color]

                  The object you create from the class definition goes out of scope.
                  Actually all objects created in the class should be destroyed when
                  the class goes out of scope any way. Destroying them explicity is
                  just a habit.


                  I posted a sample .mdb at the following url. Let me know when/if you
                  download it so I can take it off line.

                  "http://www8.brinkster. com/rkc/pcDataSheet.mdb






                  Comment

                  • Steve

                    #10
                    Re: Form Doesn't Go To New Record

                    I just downloaded the sample mdb! I really appreciate you doing that for me.

                    <<The code between <class> and </class> goes in a new class module.>> By new
                    class module, do you mean a standard module?

                    Thanks for all the help you have given!

                    Steve



                    "rkc" <rkc@yabba.dabb a.do.rochester. rr.bomb> wrote in message
                    news:hMrpc.3770 5$hY.11116@twis ter.nyroc.rr.co m...[color=blue]
                    >
                    > "Steve" <spam@nospam.sp am> wrote in message
                    > news:2yppc.7041 $zO3.3581@newsr ead2.news.atl.e arthlink.net...
                    >
                    >[color=green]
                    > > To try and learn something new and understand what you propose, I have[/color]
                    > some[color=green]
                    > > questions:
                    > > 1. What is the advantage to what you propose?[/color]
                    >
                    > The code for the textbox(s) behaviour is all in one place, in a
                    > class module.
                    >[color=green]
                    > > 2. Where specifically does your code go?[/color]
                    >
                    > The code between <class> and </class> goes in a new class module.
                    >[color=green]
                    > > 3. <<Set and load all the textboxes you want to have the behaviour into[/color]
                    > a[color=green]
                    > > collection in the form's open event.>> How do you do this? There around[/color]
                    > 25[color=green]
                    > > fields on the form, would you then cycle through the collection in the
                    > > BeforeUpdate event code?[/color]
                    >
                    >
                    >[color=green]
                    > > 4. There are a couple of memo fields, how are they handled?[/color]
                    >
                    > Same as text fields
                    >
                    >[color=green]
                    > > 5. << txtbox.Value = Replace(txtbox. Value, vbCrLf, " ")>> Why are you[/color]
                    > replacing[color=green]
                    > > a CrLf with a space rather than a null string?[/color]
                    >
                    > Because you can end up with two words run together if you don't.
                    >[color=green]
                    > > 6. What causes Private Sub Class_Terminate () to execute?[/color]
                    >
                    > The object you create from the class definition goes out of scope.
                    > Actually all objects created in the class should be destroyed when
                    > the class goes out of scope any way. Destroying them explicity is
                    > just a habit.
                    >
                    >
                    > I posted a sample .mdb at the following url. Let me know when/if you
                    > download it so I can take it off line.
                    >
                    > "http://www8.brinkster. com/rkc/pcDataSheet.mdb
                    >
                    >
                    >
                    >
                    >
                    >[/color]


                    Comment

                    • Steve

                      #11
                      Re: Form Doesn't Go To New Record

                      Tried your class out and works great!

                      I'm working on fully understanding it now :).

                      What is the difference between a module and a class?

                      Appreciate all your help.

                      Steve


                      "rkc" <rkc@yabba.dabb a.do.rochester. rr.bomb> wrote in message
                      news:hMrpc.3770 5$hY.11116@twis ter.nyroc.rr.co m...[color=blue]
                      >
                      > "Steve" <spam@nospam.sp am> wrote in message
                      > news:2yppc.7041 $zO3.3581@newsr ead2.news.atl.e arthlink.net...
                      >
                      >[color=green]
                      > > To try and learn something new and understand what you propose, I have[/color]
                      > some[color=green]
                      > > questions:
                      > > 1. What is the advantage to what you propose?[/color]
                      >
                      > The code for the textbox(s) behaviour is all in one place, in a
                      > class module.
                      >[color=green]
                      > > 2. Where specifically does your code go?[/color]
                      >
                      > The code between <class> and </class> goes in a new class module.
                      >[color=green]
                      > > 3. <<Set and load all the textboxes you want to have the behaviour into[/color]
                      > a[color=green]
                      > > collection in the form's open event.>> How do you do this? There around[/color]
                      > 25[color=green]
                      > > fields on the form, would you then cycle through the collection in the
                      > > BeforeUpdate event code?[/color]
                      >
                      >
                      >[color=green]
                      > > 4. There are a couple of memo fields, how are they handled?[/color]
                      >
                      > Same as text fields
                      >
                      >[color=green]
                      > > 5. << txtbox.Value = Replace(txtbox. Value, vbCrLf, " ")>> Why are you[/color]
                      > replacing[color=green]
                      > > a CrLf with a space rather than a null string?[/color]
                      >
                      > Because you can end up with two words run together if you don't.
                      >[color=green]
                      > > 6. What causes Private Sub Class_Terminate () to execute?[/color]
                      >
                      > The object you create from the class definition goes out of scope.
                      > Actually all objects created in the class should be destroyed when
                      > the class goes out of scope any way. Destroying them explicity is
                      > just a habit.
                      >
                      >
                      > I posted a sample .mdb at the following url. Let me know when/if you
                      > download it so I can take it off line.
                      >
                      > "http://www8.brinkster. com/rkc/pcDataSheet.mdb
                      >
                      >
                      >
                      >
                      >
                      >[/color]


                      Comment

                      • rkc

                        #12
                        Re: Form Doesn't Go To New Record


                        "Steve" <spam@nospam.sp am> wrote in message
                        news:F2vpc.7669 $zO3.7095@newsr ead2.news.atl.e arthlink.net...[color=blue]
                        > Tried your class out and works great!
                        >
                        > I'm working on fully understanding it now :).
                        >
                        > What is the difference between a module and a class?[/color]

                        A class defines a creatable object. When you use Access you
                        are using objects all the time. Recordsets, Fields, Controls
                        are all objects defined in the DAO library. Using a Class
                        module you get to define your own objects which you can
                        then create and use in the same way.



                        Comment

                        • Steve

                          #13
                          Re: Form Doesn't Go To New Record

                          Bruce,

                          I tried your suggestion and experienced the same behaviour described under my
                          reply to Dirk.

                          Steve


                          "Bruce" <bruce@aristotl e.net> wrote in message
                          news:d3b3c84d.0 405141136.4c39c 7b8@posting.goo gle.com...[color=blue]
                          > "Steve" <spam@nospam.sp am> wrote in message[/color]
                          news:<ks3pc.547 8$zO3.2582@news read2.news.atl. earthlink.net>. ..[color=blue][color=green]
                          > > Private Sub Form_BeforeUpda te(Cancel As Integer)
                          > > Dim Ctrl As Control
                          > > For Each Ctrl In Me.Controls
                          > > If Ctrl.ControlTyp e <> acLabel And Ctrl.ControlTyp e <> acCommandButton[/color][/color]
                          Then[color=blue][color=green]
                          > > If Not IsNull(Ctrl.Val ue) Then
                          > > If InStr(Ctrl.Valu e, vbCrLf) > 0 Then
                          > > MsgBox Ctrl.Controls(0 ).Caption & " Contains A Line Return." &[/color][/color]
                          vbCrLf &[color=blue][color=green]
                          > > vbCrLf _
                          > > & "The New Item Can Not Be Saved In The Database" & vbCrLf _
                          > > & "Until The Line Return Is Removed." & vbCrLf & vbCrLf _
                          > > & "Please Remove The Line Return!"
                          > > Cancel = True
                          > > Ctrl.SetFocus
                          > > Exit Sub
                          > > End If
                          > > End If
                          > > End If
                          > > Next Ctrl
                          > >
                          > > ' BeforeUpdate Event Is Used For This So InvNumber = StoreItemID When The[/color][/color]
                          Item[color=blue][color=green]
                          > > Is Saved
                          > > Me!InvNumber = Me!StoreItemID
                          > > If Me!SetThisItemA sTheDefaultNewI tem = True Then
                          > > Call SetDefaultValue s
                          > > Else
                          > > Call RemoveDefaultVa lues
                          > > End If
                          > > Me!Title.SetFoc us
                          > > End Sub
                          > >
                          > > Public Sub SetDefaultValue s()
                          > > On Error GoTo ErrorHandler
                          > > Me!Title.Defaul tValue = CQuote & Me!Title & CQuote
                          > > Me!FeatureFlag. DefaultValue = CQuote & Me!FeatureFlag & CQuote
                          > > Me!ShortDesc.De faultValue = CQuote & Me!ShortDesc & CQuote
                          > > Me!Description. DefaultValue = CQuote & Me!Description & CQuote
                          > > Me!ThumbImage.D efaultValue = CQuote & Me!ThumbImage & CQuote
                          > > Me!FullImage.De faultValue = CQuote & Me!FullImage & CQuote
                          > >
                          > > If Not IsNull(Me!Categ ory) Then
                          > > Me!Category.Def aultValue = CQuote & Me!Category & CQuote
                          > > Else
                          > > Me!Category.Def aultValue = ""
                          > > End If
                          > > If Not IsNull(Me!Secti on) Then
                          > > Me!Section.Defa ultValue = CQuote & Me!Section & CQuote
                          > > Else
                          > > Me!Section.Defa ultValue = ""
                          > > End If
                          > > If Not IsNull(Me!Aisle ) Then
                          > > Me!Aisle.Defaul tValue = CQuote & Me!Aisle & CQuote
                          > > Else
                          > > Me!Aisle.Defaul tValue = ""
                          > > End If
                          > >
                          > > Me!Alt1.Default Value = CQuote & Me!Alt1 & CQuote
                          > > Me!Alt2.Default Value = CQuote & Me!Alt2 & CQuote
                          > > Me!Alt3.Default Value = CQuote & Me!Alt3 & CQuote
                          > > Me!ListValue.De faultValue = CQuote & Me!ListValue & CQuote
                          > > Me!SalePrice.De faultValue = CQuote & Me!SalePrice & CQuote
                          > > Me!SellingPrice .DefaultValue = CQuote & Me!SellingPrice & CQuote
                          > > Me!DatePurchase d.DefaultValue = CQuote & Me!DatePurchase d & CQuote
                          > > Me!ItemCost.Def aultValue = CQuote & Me!ItemCost & CQuote
                          > > Me!ShipCost.Def aultValue = CQuote & Me!ShipCost & CQuote
                          > >
                          > > If Not IsNull(Me!Inven toryLocation) Then
                          > > Me!InventoryLoc ation.DefaultVa lue = CQuote & Me!InventoryLoc ation & CQuote
                          > > Else
                          > > Me!InventoryLoc ation.DefaultVa lue = ""
                          > > End If
                          > >
                          > > Me!Inventory.De faultValue = CQuote & Me!Inventory & CQuote
                          > > Me!ReorderPoint .DefaultValue = CQuote & Me!ReorderPoint & CQuote
                          > > Me!Quantity.Def aultValue = CQuote & Me!Quantity & CQuote
                          > >
                          > >
                          > > ExitHere:
                          > > Me!Title.SetFoc us
                          > > Exit Sub
                          > > ErrorHandler:
                          > > MsgBox Err.Description , , "Error# " & Err.Number
                          > > Resume ExitHere
                          > > End Sub
                          > >
                          > > Public Sub RemoveDefaultVa lues()
                          > > Me!Title.Defaul tValue = ""
                          > > Me!FeatureFlag. DefaultValue = ""
                          > > Me!ShortDesc.De faultValue = ""
                          > > Me!Description. DefaultValue = ""
                          > > Me!ThumbImage.D efaultValue = ""
                          > > Me!FullImage.De faultValue = ""
                          > > Me!Category.Def aultValue = ""
                          > > Me!Section.Defa ultValue = ""
                          > > Me!Aisle.Defaul tValue = ""
                          > > Me!Alt1.Default Value = ""
                          > > Me!Alt2.Default Value = ""
                          > > Me!Alt3.Default Value = ""
                          > > Me!ListValue.De faultValue = ""
                          > > Me!SalePrice.De faultValue = ""
                          > > Me!SellingPrice .DefaultValue = ""
                          > > Me!DatePurchase d.DefaultValue = ""
                          > > Me!ItemCost.Def aultValue = ""
                          > > Me!ShipCost.Def aultValue = ""
                          > > Me!InventoryLoc ation.DefaultVa lue = ""
                          > > Me!Inventory.De faultValue = ""
                          > > Me!ReorderPoint .DefaultValue = ""
                          > > Me!Quantity.Def aultValue = ""
                          > > End Sub[/color]
                          >
                          > I think I would use a somewhat different approach here. Let the form
                          > save the record. In the AfterUpdate proc of the form, save whatever
                          > key value or values you need to be able to retrieve the record that
                          > you just saved. For example, if your key value is StoreItemID and
                          > that's a long integer, do something like:
                          >
                          > dim lngPrevItemID as long ' Do this in the (General) (Declarations)
                          > section of the form so it will be available to all procs in the form
                          >
                          > Form_AfterUpdat e()
                          >
                          > lngPrevItemID = Me.StoreItemID
                          >
                          > End Sub
                          >
                          > Then in the form's Current event, check to see if you're on a new
                          > record. If so, use the key value you just stored to look up the
                          > previously saved record and load in all the default values. For
                          > example, do something like the following in Form_Current():
                          >
                          > Dim rst As Recordset
                          >
                          > If Me.NewRecord Then
                          > Set rst = CurrentDB.OpenR ecordset("selec t * from MyTable where
                          > StoreItemID = " & lngPrevItemID
                          > Me!Field1.Defau ltValue = rst!Field1
                          > ...
                          > Me!Fieldn.Defau ltValue = rst!Fieldn
                          > rst.Close
                          > Set rst = Nothing
                          > Else
                          > Me!Field1.Defau ltValue = ""
                          > ...
                          > Me!Fieldn.Defau ltValue = ""
                          > End If
                          >
                          > -or-
                          >
                          > Dim rst As Recordset
                          >
                          > If Me.NewRecord Then
                          > Set rst = Me.RecordSetClo ne
                          > rst.FindFirst "StoreItemI D = " & lngPrevItemID
                          > Me!Field1.Defau ltValue = rst!Field1
                          > ...
                          > Me!Fieldn.Defau ltValue = rst!Fieldn
                          > rst.Close
                          > Set rst = Nothing
                          > Else
                          > Me!Field1.Defau ltValue = ""
                          > ...
                          > Me!Fieldn.Defau ltValue = ""
                          > End If
                          >
                          > You might be able to do this with bookmarks as well.
                          >
                          > Hope this helps.
                          >
                          > Bruce[/color]


                          Comment

                          • Steve

                            #14
                            Re: Form Doesn't Go To New Record

                            I previously tried Bruce's suggestion and experienced the same behaviour as
                            described in my reply to Dirk. Before I try the Class route, is it different
                            from what Bruce suggested? I note that the Class uses the form's BeforeUpdate
                            event in the same way to set the default values.

                            Steve


                            "rkc" <rkc@yabba.dabb a.do.rochester. rr.bomb> wrote in message
                            news:J7xpc.1917 50$M3.79556@twi ster.nyroc.rr.c om...[color=blue]
                            >
                            > "Steve" <spam@nospam.sp am> wrote in message
                            > news:F2vpc.7669 $zO3.7095@newsr ead2.news.atl.e arthlink.net...[color=green]
                            > > Tried your class out and works great!
                            > >
                            > > I'm working on fully understanding it now :).
                            > >
                            > > What is the difference between a module and a class?[/color]
                            >
                            > A class defines a creatable object. When you use Access you
                            > are using objects all the time. Recordsets, Fields, Controls
                            > are all objects defined in the DAO library. Using a Class
                            > module you get to define your own objects which you can
                            > then create and use in the same way.
                            >
                            >
                            >[/color]


                            Comment

                            • rkc

                              #15
                              Re: Form Doesn't Go To New Record


                              "Steve" <spam@nospam.sp am> wrote in message
                              news:uNxpc.7784 $zO3.1511@newsr ead2.news.atl.e arthlink.net...[color=blue]
                              > I previously tried Bruce's suggestion and experienced the same behaviour[/color]
                              as[color=blue]
                              > described in my reply to Dirk. Before I try the Class route, is it[/color]
                              different[color=blue]
                              > from what Bruce suggested? I note that the Class uses the form's[/color]
                              BeforeUpdate[color=blue]
                              > event in the same way to set the default values.[/color]


                              The class method is just a modified way of doing the same thing you were
                              doing in the first place. Bruce is using a query to retrieve all the fields
                              from
                              the previously entered record.

                              If you use the form in the sample .mdb you downloaded to enter new records
                              you'll see that it does not exibit the same behaviour as you described. As
                              far
                              as why that is... I really don't have a clue.


                              Comment

                              Working...