Results 1 to 10 of 10
  1. #1
    joekuhn is offline Novice
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Posts
    18

    SendKey

    I am using a "SendKey" macro in my database and it works ok except the first time I use it it shows a warning message and when I click ok it turns off the Numeric Lock. How can I prevent the warning message from coming up and avoid the Numeric Lock from being turned off? The database is in a trusted location and I am using Access 2007 with Windows Vista. Help!
    I have the setwarnings on "no" in the macro and the following message still comes up: "Microsoft Office Access Security Notice
    A potential security concern has been identified.
    Warning: It is not possible to determine that this content came from a trustworthy source. You should leave this content disabled unless the content provides critical functionality and you trust its source.
    File Path: C:\.. -FT OFFICE\OFFICE1\ACCWIZ\UTILITY.ACCDA
    This file might contain unsafe content that could harm your computer. Do you want to open this file or cancel the operation?


    More information
    Open"

    I also tried the "DoCmd.SetWarnings False" in the "On Open" property and the same thing happens. Any suggestions on how I can get around this?

    "My Documents" folder which contains all my files is declared a trusted location. I am assuming that that includes all subfolders.
    joekuhn

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    joe,

    isn't this the 2nd time you've posted this thread? did you get anything from the last time it was posted?

    also, is the message due to the macro security settings? what are they?
    what is the sendkeys action? why keys are you sending?

    it sounds like it's an internal setting like a security setting or something. in that case, setwarnings does not apply and can't help. have you googled "ms access 2007 security warning"??

    I wasn't aware of either, that utility is apparently needed when sendkeys is called: http://support.microsoft.com/kb/145773

    a similar problem also hatched a solution here: http://www.dbforums.com/microsoft-ac...7-runtime.html

  3. #3
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    I gave a few ideas in the previous thread but they didnt work. And assuming the rest of you are like me, nobody would have opened that thread seeing as though there were quite a few replies anyway.It's probably best that he restarted the thread.

  4. #4
    joekuhn is offline Novice
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Posts
    18
    Thanks for your reply. Yes this is my second post. It was suggested I try a different forum so I posted under "security".
    I don't know the macro security settings. I can't find them anywhere.
    The sendkey action is "Sendkeys" arguments "0,No". I need to enter the number "0" automatically in a control on a subform before the main form is saved or other parts of my database wil not function. That is why I use "SendKey".
    I am looking at the three suggestions you gave me to see if I can find a solution.
    I tried to add the "Access utility add-in" by running my installation disc and selecting "Add or remove features" but there is no utility add-in listed.

  5. #5
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    if that's all you need to do, you don't need sendkeys. write the value using vba and save the form using the same method.

    sendkeys is risky anyway. I think most technicians will say the same thing too.

    Now...the API that shuts the keyboard OFF is very useful! =)

  6. #6
    joekuhn is offline Novice
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Posts
    18
    I tried using a "setvalue" macro instead of "sendkeys" and it gets me to the control in the subform but does not show the value in the control and I cannot save the subform. I tried to write the value in VBA but could find how to do it. Any suggestion is appreciated.

  7. #7
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    You really shouldn't ever setwarnings to No and leave it that way. This disables any error messages that you 'should' get within MSAccess and any code. It can be dangerous leaving error messages disabled like this since code will 'silently' fail which could lead to other problems (including data related issues). The only time I do a SetWarnings to No is before I run some append queries and I don't want the user to get a message prompting to do the append. But I then make absolutely sure I do a SetWarnings Yes when the query is done or an OnError event.

    I'm not sure where it's located in the MSAccess 2007/2010 menu system but there is a way to change the Macro Security to low (which I always do). I think this is under Macro Security. You would just need to open MSAccess and change this setting on each of the user's computer (one time deal). (I'm not sure how it's done programmatically since I always change it whenever MSAccess is installed on a user's computer.)

    You can also check this post to see if this might be part of the problem as well:
    https://www.accessforums.net/securit...ork-10106.html

    If you need to populate a value in a field though on a form, SendKeys is not really the best method to do this. I believe in a Macro you would use the SetValue to do this. In vba coding, it's even easier where you just write something like this: Forms!MyFormName!MyFieldName = 0 (or me!MyFieldName = 0) in any event such as the Form's BeforeUpdate event.

  8. #8
    joekuhn is offline Novice
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Posts
    18

    Sendkey

    Thank you for you suggestions. I was able to solve my problem by using SetValue but it took me a while to find out where to put the code in the Before Update, in the subform or the main form. It is all working ok now.

  9. #9
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    If you're trying to write a value to a field on the subform, try (using vba):

    Forms!MyMainFormName!MySubformName!MyFieldName = 0

    You may want to get in the habit of using vba instead of macros. They really offer a lot more versatility and once you get used to writing vba, you'll really start to enjoy coding a lot more (and will never go back to writing any macros). I used to write macros all the time when I started developing until I discovered the power of writing vba code.

    To write vba code, select the field on the form (or select the form itself to code events around the entire form - ie. you'll see the word 'Form' in the upper left corner of the properties box instead of a field name). Then select the Event (ie. AfterUpdate, BeforeUpdate, OnFocus, etc...). Then in the dropdown box for the event, select [Event Procedure]. Then click the 3 dots to the right of the dropdown box. This will take you to the coding screen where you can write vba code against that event.

    Note: programming events based on the form itself are quite powerful whereas you can write code such as in the BeforeUpdate so that it writes values to any fields before the record itself is updated.

    Example of writing to a field called: DateModified and ModifiedBy on the form before the record is updated (select the form and then in the BeforeUpdate event of the form, select [Event Procedure] and then the 3 dots.)

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Me!DateModified = Now()
    Me!ModifiedBy = GetUser() <- see code repository (How to return the user - Getuser) for how to easily return the user's windows loginID: https://www.accessforums.net/code-re...thod-7675.html (for a secure method on returning the user's loginID but there are also other easier ways to do this such as using Environ)
    End Sub

    The above example would write in when the record was last modified and who modified it. This is a great way to track this info.

    Another Form Event I'll often use is the OnOpen or OnLoad event for the form. An example would be writing code to resize the form when it opens (good for forms where the Popup property = True to make them popup type forms)...

    Private Sub Form_Open(Cancel As Integer)
    DoCmd.MoveSize , 200, , 5000 <- make the popup form show 200 pixels down from the top and 5000 pixels in height.
    End Sub

    I personally really like making all my forms popup type forms. This way I can easily control the flow of the program itself and prevent users from wandering into the MSAccess menu items when they shouldn't be (also make the Form's Modal property = True so that they cannot click anywhere else except on a field/button the form itself.) See any example by pkstormy in the code repository for more examples of how to do this if you're interested.

  10. #10
    joekuhn is offline Novice
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Posts
    18
    Thank you again for your information. It is appreciated and will make good use of it.

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

Similar Threads

  1. 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