Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2007

    Unanswered: set defaults in data enty page to values from previous record

    I am trying to set up a simple data access page which is linked to a table in MSAccess. Three of the fields are likely to require the user to enter the same data from record to record (though not always). I would like to set a control (cmdbutton) on the DAP to open a blank page to enter a new record, but to set the default values for the first three fields to that of the last record entered.
    Now the table also has a field called IndexID which is the primary key and which is an autonumber field. I got a sample code from the MSKnowledgeBase which uses an SQL statement embedded in VB to achieve the results. The example however was based on the Northwind database on a page that was linked to a query instead of a table, and perhaps other data differences I am missing.
    So I modified the code as follows and placed it in my page.
    <SCRIPT language=vbscript event=onclick for=cmdCopyRecordSQL>
    <!---->dim strSQL
    strSQL = "INSERT INTO Checks (StaffID, ProgramLocation, County) " &_
    "Select StaffID, ProgramLocation, County " &_
    "FROM Checks WHERE Checks.IndexID =" & txtIndexID.Value
    MSODSC.Connection.Execute strSQL

    I receive script errors when trying to run it.

    An error has occurred on the script on this page.
    This command is not available.

    then it references the line and first character of the

    on the second try I get another script error referencing the
    An error has occurred on the script on this page!
    Syntax error missing operator in query expression “Checks.IndexID = “
    URL: accdp://14564676/

    I am unused to VB script. any help or direction to pursue would be greatly appreciated.

  2. #2
    Join Date
    Jun 2005
    Richmond, Virginia USA
    Provided Answers: 19
    Sorry, wrong post!
    Hope this helps!

    The problem with making anything that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Sep 2007
    When using MS Script Editor, what exactly do I do to assign the code to the particular controls? Is it all just one long script?
    I can just paste in the text example that you gave me and change the field and control names?
    Thanks for responding. It seems a lot simpler than I realized, but I bet I am missing a lot of basic things that I am ignorant of.

  4. #4
    Join Date
    Jan 2007
    Provided Answers: 12
    ravenouspi - please do not post duplicate questions. If needs be you can bump your thread after a couple of days of inactivity.

    In response to your question - have you tried simply hardcoding the value for now, just to check that the code works?
    strSQL = "INSERT INTO Checks (StaffID, ProgramLocation, County) " &_
    "Select StaffID, ProgramLocation, County " &_
    "FROM Checks WHERE Checks.IndexID = 1"
    Home | Blog

  5. #5
    Join Date
    Sep 2006
    I would consider inserting a Foreign Key into the Check Table and another Table with these "Constants" and don't store this information in the Checks table at all.


Posting Permissions

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