3

I am trying to execute the command toggletable or showall function on a javascript page that has the tables information hidden until you click on the + button next to it. I would like to just make these automaticly expanded for printing purposes. Here is what I have so far.

Function PrintWebPage()
Const OLECMDID_PRINT = 6
Const OLECMDEXECOPT_PROMPTUSER = 1
Const OLECMDEXECOPT_DONTPROMPTUSER = 2

Dim ie As Object
Dim strWebPage As String, stblAutoNumber(99999) As String, stblBadgeNumber(999999) As String, stblShopNumber(99999) As String

DoCmd.SetWarnings False
' Connect to DB
Set db = CurrentDb()

' Select Statement for scrolling through everyone
sqlString = "SELECT tblPersonal.AutoNumber, tblPersonal.[Badge Number], tblPersonal.Shop , tblPersonal.[Last Name] FROM tblPersonal WHERE tblPersonal.[Shop] = " & """" & ShopUserATMS & """" & ";"

' Sets mRecordset to query the database
Set mRecordset = db.OpenRecordset(sqlString)

' Goes to first record of the generated list
mRecordset.MoveFirst
Do While Not mRecordset.EOF
    ' Scroll through personal List
    stblAutoNumber(i) = mRecordset("AutoNumber")
    CheckBadgeNull = mRecordset("Badge Number")
    If IsNull(CheckBadgeNull) = True Then
        GoTo NoRec:
    End If
    stblBadgeNumber(i) = mRecordset("Badge Number")
    stblShopNumber(i) = mRecordset("Shop")
    strWebPage = "https://was3.nnsy.navy.mil/atms/components/supervisor/atms_supv_detail.cfm?BADGE=" & stblBadgeNumber(i)
    DoEvents: DoEvents: DoEvents
    Set ie = CreateObject("internetexplorer.application")


    ie.Navigate strWebPage

    Do Until ie.Busy = False
        sSleep (1)
    Loop
    Call ie.Document.parentWindow.execScript("toggletable(Quals)", "JavaScript")
    'ie.getelementsbyid("Showall") = True
    'stblShopNumber(99) = ie.Document.execcommand("toggletable", False, Null)
    ie.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER

    sSleep (2)
NoRec:

Loop

    ie.Quit

    Set ie = Nothing

End Function

It gives me access denied when I use the following command: Call ie.Document.parentWindow.execScript("toggletable(Quals)", "JavaScript")

Any help is appreciated. Beating my head on this one for over 8 hours...

1
  • did you end up solving the problem? (and I'm not talking about DontFretBrett's alternative method, since that is not an answer to your question). If you did figure out why Access Is Denied is thrown, please do share since I am having the same problem. Commented Dec 17, 2012 at 10:31

2 Answers 2

1

You need to enable "Allow active content to run in files on My Computer" option from Internet Options-->Advanced-->Security. If you want to change this IE setting programmatically, below is the vbscript code for it:

Const HKEY_CURRENT_USER = &H80000001    
strComputer = "."
dwValue = 0
Set objReg = GetObject("winmgmts:" & "{impersonationLevel=impersonate}\\" & strComputer & "\root\default:StdRegProv")   
strKeyPath = "Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_LOCALMACHINE_LOCKDOWN"
objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath,"iexplore.exe",dwValue

set dwValue to 0 to enable, and 1 to disable the IE setting.

Sign up to request clarification or add additional context in comments.

Comments

0
Dim IE As New InternetExplorer
IE.Visible = True
IE.navigate "http://www.google.com"
Do: DoEvents: Loop Until IE.readyState = READYSTATE_COMPLETE
IE.navigate "javascript:alert('hi');"

3 Comments

would you by any chance have the answer to his problem (without using the workaround you suggested, and without using any workaround, but instead the actual answer to the question he asked)...? If by any chance you do, I'd love to know, thanks.
I don't think it's a work around, I'm pointing out a different way to execute javascript, and it probably won't throw the access denied error. Are you having the access denied problem too?
yeah I am getting access denied when using .execScript, do you have any idea why thats happening?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.