Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2006
    Posts
    8

    autofill default values with last value entered (solved)


    OK.. Here's my situation. Ive got a for with the following fields and example data:

    Autonumber (Hidden)
    Name: BG
    Date: 12-20-06
    Machine: 4APC
    Operation: 2
    Tool: MAS20750
    Time Changed: 22:45

    On a daily basis I need to enter values in here. I'll go through about 15-20 records where the first 4 fields are all the same (Name, Date, Machine, and Operation). Ideally, instead of having to type all this crap in every time, I'd like to have my new record automaticall fill in the value for these as whatever the last ones I put in were.

    What I have done is created a select query that returns the last record entered according to the Autonumber, by setting the TopValue to 1. I saved this as QLastRecord

    Then I created a Macro. One line, with the SetValue action.
    I set my Item to this: [Forms]![Tool Changes]![Name].[DefaultValue]
    I set my Expr to this: [QLastRecord]![Name]

    (I pulled both of these from the expression builder, so I know its not a mistype in the expression)

    When I run the macro, I get this:

    Microsoft Access can't find the name 'QLastRecord" you entered in the expression.

    It seems as though the macro is trying to find a form under the name QLastRecord, so I tried putting [Queries]! in front of this, to direct it to the query object, but i end up with basically the same thing.

    Is it not possible for a macro to pull a value for SetValue from a query?

    Please advise, and thanks

  2. #2
    Join Date
    Dec 2006
    Posts
    8

    Got it

    In case anyone else was wondering, I got this figured out, and it works great.

    I put a command button at the bottom of the form with the following code attached:



    Private Sub NewRecord_Click()
    On Error GoTo Err_NewRecord_Click

    'Define variables to hold the info for each field to be updated
    Dim VarName As String
    Dim VarDate As Date
    Dim VarMach As String
    Dim VarOp As String

    'Set the variable values to current field values
    VarName = Forms![Tool Changes]!Name
    VarDate = Forms![Tool Changes]!Date
    VarMach = Forms![Tool Changes]!Machine
    VarOp = Forms![Tool Changes]!Operation

    'Start a new record
    DoCmd.GoToRecord , , acNewRec

    'Input the variable into the field
    Forms![Tool Changes]!Name = VarName
    Forms![Tool Changes]!Date = VarDate
    Forms![Tool Changes]!Machine = VarMach
    Forms![Tool Changes]!Operation = VarOp

    'Move the cursor to the Tool field for entry


    Exit_Command14_Click:
    Exit Sub

    Err_Command14_Click:
    MsgBox Err.Description
    Resume Exit_Command14_Click

    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 0
    Last Post: 11-10-2008, 12:32 PM
  2. Any function regarding remainder??? [Solved]
    By wasim_sono in forum Forms
    Replies: 2
    Last Post: 10-21-2006, 01:53 AM
  3. How to use array? [ solved] Thanks.
    By wasim_sono in forum Programming
    Replies: 0
    Last Post: 10-20-2006, 12:00 AM
  4. Default Values
    By twainscott in forum Programming
    Replies: 0
    Last Post: 09-14-2006, 11:18 AM
  5. Unmatched data entered with data in table
    By boreda in forum Access
    Replies: 0
    Last Post: 07-28-2006, 09:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums