Results 1 to 10 of 10
  1. #1
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402

    sendkey action

    Hi All

    I have been asked if its possible by using the sendkeys function to do the following


    form1 contains a tick box called "ONHOLD" when ticked and set to true, is it possible to use sendkeys to automatically add the time and date to a textbox on form2?

    I have only ever used sendkeys on one form, is it even possible to use sendkeys and reference another forms text box?

    im not sure this can be done, has anyone else done this in the past?

    what I am after is this


    form1
    on the after update event of the onhold tickbox



    add text automatically to

    forms!form2.textbox

    any help would be great

    steve

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I have no idea how SendKeys would be involved in populating date and time. Simply:

    Forms!form2.textboxname = Now()
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    As June7 said, there's really no reason/need to use SendKeys, for this job, and definite reasons not to! SendKeys has always been problematic, causing the NumbersLock key to toggle off and on, randomly, and as of version 2007, SendKeys may fail, unless a pre-version 2007 copy of Access is still installed on a given machine! And note the word may...even this isn't consistent!

    The rule of thumb, vis-à-vis using SendKeys, is that you only do it if there is absolutely, positively, without a shadow of a doubt no other route available to accomplish the task at hand!

    Linq ;0)>

  4. #4
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi Guys

    thanks for the reply's and sorry for the late reply.

    I am in the unfortunate position of having to take over the development of a system from a previous developer who designed this system

    the problem I have is that the managers love the way the comments work at the moment as it cuts down on the amount of mouse clicks required,

    the text box on form1 is a memo field, this is locked until a user clicks the add comment button.

    when the button is clicked it runs this code

    Private Sub EditCommentButton_Click()
    On Error GoTo EditCommentButton_Click_Error
    Me.Comments.Enabled = True
    Me.Comments.Locked = False
    DoCmd.GoToControl "Comments"

    'set the cuser to the top of the text box
    Me.Comments.SelStart = 0
    SendKeys ("{up}")
    SendKeys ("{ENTER}")
    SendKeys ("{up}")
    Me.Comments.SetFocus
    SendKeys ("{up}") & Now & " - " & UserFullName & " "
    SendKeys ("{NUMLOCK}")
    On Error GoTo 0
    Exit Sub

    this for works and allows the end user to just start typing information, the date and time plus the users full name is automatically entered.

    what I am now being asked to do is

    I have been asked if users can add comments into this memo field when a button is clicked on another form2 that places a job on hold

    for example this
    code behind on hold button on form2

    Forms.form1.Comments.Enabled = True
    Forms.form1.Comments.Locked = False
    Forms.form1.Comments.SetFocus
    Forms.form1.Comments.SelStart = 0
    Forms.form1.Comments SendKeys("{up}")
    Forms.form1.Comments SendKeys("{ENTER}")
    Forms.form1.Comments SendKeys("{up}")
    Forms.form1.Comments SetFocus
    Forms.form1.Comments SendKeys("{up}")
    Forms.form1.Comments SendKeys & Now & " - " & UserFullName & " " & Me.Machine & " Placed On Hold "
    Forms.form1.CommentsSendKeys ("{NUMLOCK}")
    Forms.form1.Comments.Enabled = False

    the code above produces the following error

    Compile Error
    Expected Function or Variable

    now if it was down to me I would totally redesign the comments system but office politics prohibits this!!!!

    is this even possible to do

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I really don't understand the use of SendKeys in this context.

    If you want to populate a control on another form, just reference that form and control or the field the textbox is bound to. Don't even have to enable or unlock.

    Forms!form1.Comments = Now & " - " & UserFullName & " " & Me.Machine & " Placed On Hold "
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi June

    thanks for getting back

    I was trying to use the send keys action to create a new line in the comments box before creating the text, otherwise all the original comments get over written.

    I think I will press my case and get the management to allow me to change the comments system entirely

    I must say that I am not a fan of taking over someone else development

    Many Thanks

    Steve

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    New line can be programmatically concatenated

    Forms!form1.Comments = Forms!form1.Comments & IIf(IsNull(Forms!form1.Comments), "", vbCrLf) & Now & " - " & UserFullName & " " & Me.Machine & " Placed On Hold "

    Ideally, each comment would be a separate record in a related table.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi june7

    That's fantastic, and so very obvious when it's shown like that, many many thanks, I will implement this first thing when I'm back on site in the morning

    Steve

  9. #9
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi June7

    I have applied the code you sent and its working, its not overwriting the comments which is fantastic many many thanks.

    the reason I think that the send key action was being used is because all new comments are being shown first, that is they are being put into the top of the memo field, the code I have implemented puts all new comments at the bottom on the memo field

    is there a way using code that all new text entries go to the top of the memo field?


    Many thanks again for your help

    Steve
    Last edited by June7; 03-25-2015 at 10:31 AM.

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Reverse the concatenation.

    Forms!form1.Comments = Now & " - " & UserFullName & " " & Me.Machine & " Placed On Hold " & IIf(IsNull(Forms!form1.Comments), "", vbCrLf) & Forms!form1.Comments

    Really would be better design for each comment to be a record in a related table.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Sendkey alternative help
    By Madmax in forum Access
    Replies: 1
    Last Post: 04-10-2012, 10:46 AM
  2. action queries together
    By slimjen in forum Queries
    Replies: 3
    Last Post: 01-27-2012, 12:52 AM
  3. Can't run this action???
    By wwg77 in forum Programming
    Replies: 2
    Last Post: 02-02-2011, 03:22 PM
  4. SendKey
    By joekuhn in forum Security
    Replies: 9
    Last Post: 12-26-2010, 09:58 PM
  5. SendKey
    By joekuhn in forum Access
    Replies: 7
    Last Post: 11-17-2010, 01:27 PM

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