Results 1 to 6 of 6

Thread: SendKeys

  1. #1
    Join Date
    May 2003
    Posts
    26

    Unanswered: SendKeys

    I am trying to automate copying the contents of a previous record in a form by using the Ctrl+' keys in a macro using the Sendkeys action.

    I can't seem to get this to work in a Macro anyone have any suggestions? I've tried various statements using ....

    ^'
    {^}(')
    "^'"
    "{^}'"

  2. #2
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Talking Re: SendKeys

    Originally posted by ramonas
    I am trying to automate copying the contents of a previous record in a form by using the Ctrl+' keys in a macro using the Sendkeys action.

    I can't seem to get this to work in a Macro anyone have any suggestions? I've tried various statements using ....

    ^'
    {^}(')
    "^'"
    "{^}'"
    If you have two textBox on your form txt1 and txt2 then past this littel code. The goal of it is to copy what you type in txt1 and past it in txt2


    Private Sub txt1_Exit(Cancel As Integer)
    txt1.SelStart = 0
    txt1.SelLength = Len(txt1)
    SendKeys "^{INSERT}", True

    txt2.SetFocus
    SendKeys "+{INSERT}", True
    End Sub

  3. #3
    Join Date
    Nov 2003
    Location
    LONDON
    Posts
    238

    Re: SendKeys

    Originally posted by ramonas
    I am trying to automate copying the contents of a previous record in a form by using the Ctrl+' keys in a macro using the Sendkeys action.

    I can't seem to get this to work in a Macro anyone have any suggestions? I've tried various statements using ....

    ^'
    {^}(')
    "^'"
    "{^}'"
    The best way of copying a record is to use SQL. Save the Primary Key of the record you have just created and then use an INSERT INTO SQL statement to create a copy of the record.

    Alternatviely you could copy the contents of each field in the form to the DefaultValue property of the field. A new record will have as there default values the contents of the previous record. Use the AfterUpdate event of each field to copy the contents eg:

    Private Sub txtMyTextBox_AfterUpdate()
    Me("txtMyTextBox").DefaultValue = Me("txtMyTextBox").Value
    End Sub

    You should avoid using SendKeys as they are unreliable and can be overridden by Windows events and Macros should never be used as you have no Erorr handling with them

  4. #4
    Join Date
    May 2003
    Posts
    26

    Re: SendKeys

    I belive this will only work for NEW records. My scenario is I have an imported text file which was in a grouped report format.

    When the import came over I have the group name in only the first record of each group. I need to have the group name for each record and there are over 250000 records.

    Could code somehow look at the next record to determine if it is null and if so return the value of the previous record?

    Any help would be greatly appreciated.


    Originally posted by justin_tighe
    The best way of copying a record is to use SQL. Save the Primary Key of the record you have just created and then use an INSERT INTO SQL statement to create a copy of the record.

    Alternatviely you could copy the contents of each field in the form to the DefaultValue property of the field. A new record will have as there default values the contents of the previous record. Use the AfterUpdate event of each field to copy the contents eg:

    Private Sub txtMyTextBox_AfterUpdate()
    Me("txtMyTextBox").DefaultValue = Me("txtMyTextBox").Value
    End Sub

    You should avoid using SendKeys as they are unreliable and can be overridden by Windows events and Macros should never be used as you have no Erorr handling with them

  5. #5
    Join Date
    Nov 2003
    Location
    LONDON
    Posts
    238

    Re: SendKeys

    Originally posted by ramonas
    I belive this will only work for NEW records. My scenario is I have an imported text file which was in a grouped report format.

    When the import came over I have the group name in only the first record of each group. I need to have the group name for each record and there are over 250000 records.

    Could code somehow look at the next record to determine if it is null and if so return the value of the previous record?

    Any help would be greatly appreciated.
    This is a different question! To fill in the missing records you should use a SQL statement. First you will need some way of identifying each group other wise this will not work. The SQL would look like:

    UPDATE MyImportTable
    SET MyGroupName = "Group Name"
    FROM MyImportTable
    WHERE (MyGroupName Is NULL)
    AND (This is where you will need to be able to identify each group in the records. Maybe another field finds the group or you could join the table to the source table)

  6. #6
    Join Date
    May 2003
    Posts
    26

    Re: SendKeys

    Don't think this approach will work either. There are two fields (Group and Detail). For the Group field the Detail value is blank and for the Detail field the Group value is blank. Here is an example of the table after import.

    http://www.saphier.com/table.htm



    Originally posted by justin_tighe
    This is a different question! To fill in the missing records you should use a SQL statement. First you will need some way of identifying each group other wise this will not work. The SQL would look like:

    UPDATE MyImportTable
    SET MyGroupName = "Group Name"
    FROM MyImportTable
    WHERE (MyGroupName Is NULL)
    AND (This is where you will need to be able to identify each group in the records. Maybe another field finds the group or you could join the table to the source table)
    Last edited by ramonas; 11-11-03 at 11:43.

Posting Permissions

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