Results 1 to 3 of 3
  1. #1
    julia_877 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    4

    Create two records at the same time based on text box input


    Hello,

    I am trying to write a code, to create a 2nd record while the current record is being created. I have written this code in the command_click event of the last button ('Exit Form' button) that is clicked on the form to close it.

    I want to create a new record (or 2nd record) if the value of a particular textbox is < 25 (i.e. continue with creating the current record based on the values entered in the open form and also create a second record if the width entered happens to be less than 25). The new record should have the same values as the current record that is being created, except for the primary key and few other fields. The primary key (RollCut) will be XXXXX-1 for 1st record and XXXXX-2 for 2nd record (XXXXX being the value of "Ticket" field).

    -----------------

    Private Sub Command105_Click()
    On Error GoTo Err_Command105_Click

    If Me.WbWidth.Value < 25 Then
    DoCmd.GoToRecord , , acNewRec
    'Add statement to use same values as the current record
    [RollCut] = [Ticket] & "-2"
    'Add statements to change some of the values in 2nd record.
    End If

    DoCmd.Close

    Exit_Command105_Click:
    Exit Sub

    Err_Command105_Click:
    MsgBox Err.Description
    Resume Exit_Command105_Click

    End Sub

    ------------------

    I also get an error message, "you can't go to the specified record". Can anyone please help me with the code?

    Thanks,
    JK

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try saving the current record before attempting to move to a new record.

  3. #3
    julia_877 is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    4
    RuralGuy: Thanks! I was able to create two records at one time.

    Also, do you know if there is any shortcut to copy (or use) the current record values for the 2nd record? There are around 25 fields, do I have to assign the value of each field here?

    Quote Originally Posted by RuralGuy View Post
    Try saving the current record before attempting to move to a new record.

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

Similar Threads

  1. Replies: 3
    Last Post: 08-25-2010, 09:03 AM
  2. Replies: 2
    Last Post: 06-17-2010, 04:15 PM
  3. Replies: 1
    Last Post: 06-14-2010, 02:31 AM
  4. Input data In unbound text box
    By chu3w in forum Forms
    Replies: 1
    Last Post: 04-01-2010, 10:21 AM
  5. Converting all text input to lower case
    By aommaster in forum Forms
    Replies: 6
    Last Post: 08-05-2009, 05:43 AM

Tags for this Thread

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