Results 1 to 8 of 8
  1. #1
    2 Star Lounger
    Join Date
    Apr 2003
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form Headers (2000)

    Hello all --

    I'm trying to create a form that will allow me to order books. However, I need a few fields to default in from the previous entry, namely the Order Type and Department fields. On the initial startup, having them blank is fine. But if the user adds additional books, I want the choices from the previous book to default in to the next one. Can anyone help? The file is attached.

    Thanks!
    Kindra
    Attached Files Attached Files

  2. #2
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Form Headers (2000)

    Kindra

    Can you explain a bit further about "..A few fields to default in from the previous entry..."

    I have had a look at your form but the Select the Media Type combo is not updating!

    Jerry
    Jerry

  3. #3
    2 Star Lounger
    Join Date
    Apr 2003
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Headers (2000)

    The Media Type combo can be updated if you delete the MEDIA_TYPE control source in the properties screen. sorry about that, I was trying to pare the form down to the bare minimum and deleted the MEDIA_TYPE field in the ORDERS table and forgot to change that.

    I want the top 2 fields to stay with the entire order until the user has exited out of the application. For example, if the user has selected:

    Order Type = Out-of-Print
    Department = Art

    I don't want those updated fields to disappear if the user clicks the Add button (which is on my form, but not this stripped down version). Right now, they do.

    Does that make sense?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Form Headers (2000)

    You can use the On Current event of the form to do this. The following code is inpired by ACC2000: Fill Record with Data from Previous Record Automatically, although it is much simpler and less general than Microsoft's example.

    Private Sub Form_Current()
    Dim rst As Object

    ' Get out if we're not on a new record
    If Me.NewRecord = False Then Exit Sub

    ' Copy of record source of form
    Set rst = Me.RecordsetClone
    ' Continue if an error occurs
    On Error Resume Next
    rst.MoveLast
    ' Get out if an error occurred (no records)
    If Err Then GoTo ExitHandler
    On Error GoTo ErrHandler

    ' Set default values of Order Type and Department
    Me.cboOrderType.DefaultValue = rst!Order_Type
    Me.cboDept.DefaultValue = rst!Department

    ExitHandler:
    ' Clean up
    Set rst = Nothing
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Form Headers (2000)

    Oh, and by the way, may I recommend you to compact your database from time to time (Tools | Database Utilities | Compact and Repair Database...)

    Your database went from over 400 KB to about 200 KB, and zipped to just 14 KB!

  6. #6
    2 Star Lounger
    Join Date
    Apr 2003
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Headers (2000)

    Thanks for the tip Hans!

    How would I go about using this code for a text field that I want to default over? It's working for my combo boxes but not my text box (which is on MY form, not on my attached form)? I'm getting the dreaded #Name? in my text field that I'm trying to carry over.

    Thanks!

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Form Headers (2000)

    Is the text box bound to a field in the record source of the form? If so, the code should work, but you have to adapt it depending on the field type.

    For numeric fields:
    Me.[ControlName].DefaultValue = rst![FieldName]

    For text (and memo) fields:
    Me.[ControlName].DefaultValue = Chr(34) & rst![FieldName] & Chr(34)

    Chr(34) is the double quote character.

    For date fields:
    Me.[ControlName].DefaultValue = "#" & Format(rst![FieldName], "mm/dd/yyyy") & "#"

    You can omit the square brackets around the name of the control and of the field if they contain no spaces and other "unusual" characters (unusual for names in Access, that is)

  8. #8
    2 Star Lounger
    Join Date
    Apr 2003
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Headers (2000)

    THANK YOU Hans!

    <img src=/S/fanfare.gif border=0 alt=fanfare width=31 height=23>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •