|
Home > Archive > MS Access and Internet > October 2005 > using VBA to get the proxy server
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
using VBA to get the proxy server
|
|
| Luke Bellamy 2005-10-27, 8:31 am |
| Hi - I would like to connect to the net from my Access 2002 app
and basically implement an Automatic Check for updates facility.
I was going to use the WinHttpRequest object library but it seems
I need to specify the proxy.
Is their a way to get the Internet explorer proxy settings using VBA?
Is their a better way than using the WinHttpRequest objects?
Thanks
---------------
Luke Bellamy
Newcastle, Australia
| |
| John Mishefske 2005-10-27, 8:31 am |
| Xref: TK2MSFTNGP08.phx.gbl microsoft.public.access.internet:35611
Luke Bellamy wrote:
> Hi - I would like to connect to the net from my Access 2002 app
> and basically implement an Automatic Check for updates facility.
> I was going to use the WinHttpRequest object library but it seems
> I need to specify the proxy.
>
> Is their a way to get the Internet explorer proxy settings using VBA?
> Is their a better way than using the WinHttpRequest objects?
>
>
This may get you started. A Google search may provide more detailed info:
The defines:
Public Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" _
(ByVal hOpen As Long, _
ByVal sUrl As String, _
ByVal sHeaders As String, _
ByVal lLength As Long, _
ByVal lFlags As Long, _
ByVal lContext As Long) As Long
Private Const INTERNET_OPEN_TYPE_P
RECONFIG = 0
Private Const INTERNET_OPEN_TYPE_D
IRECT = 1
Private Const INTERNET_OPEN_TYPE_P
ROXY = 3
Private Const INTERNET_OPEN_TYPE_P
RECONFIG_WITH_NO_AUT
OPROXY = 4
The code:
' open Internet connection
If Len(sProxyName) > 0 Then
hOpen = InternetOpen("yourAppName", INTERNET_OPEN_TYPE_P
ROXY, sProxyName, "", 0)
Else
' the INTERNET_OPEN_TYPE_P
RECONFIG option uses registry proxy info
hOpen = InternetOpen("yourAppName", INTERNET_OPEN_TYPE_P
RECONFIG, "", "", 0)
End If
If hOpen <> 0 Then
hOpen = InternetOpen("yourAppName", INTERNET_OPEN_TYPE_P
RECONFIG, "", "", 0)
--
'---------------
'John Mishefske
'---------------
| |
| Jesper Fjølner 2005-10-27, 8:31 am |
| > Hi - I would like to connect to the net from my Access 2002 app
> and basically implement an Automatic Check for updates facility.
> I was going to use the WinHttpRequest object library but it seems
> I need to specify the proxy.
> Is their a way to get the Internet explorer proxy settings using VBA?
> Is their a better way than using the WinHttpRequest objects?
I've been trying to do something similar and I'm still working on it. I'd be
interested in hearing about if you get it to work.
The following is what I have so far. I found the function below here
http://www.databasejournal.com/feat...cle.php/3513061 where
you can download the rest of the code.
Iit downloads a specified file from an FTP-adresse and it seems to work.
What I still need to figure out is:
1) While I can get it to download a file from ftp.mydomain.com and don't
know how to download from ftp.mydomain.com/foldername
2) I don't want to download new files all the time. When initiating a
download, I'd like it to check the datestamp of the local file and of the
ftp-file and if the latter is newer proceed with the download.
Alternatively, I have a menuoption called "Check for updates" and the
download is initiated when pressing this and it'll complete the download
whether or not the remote file is newer than the local file.
However, for a simple download this works:
Public Function DownloadFTPFile(ByVa
l sFile As String, sSVR As String, sFLD
As String, sUID As String, sPWD As String) As String
'Example:
'DownloadFTPFile("FileNameOnFtpServer",ftp.yourdomain.com"," NameOfFileToDownload
","FTPusername",FTPpassword")
Dim sLocalFLD As String
Dim sScrFile As String
Dim sTarget As String
Dim iFile As Integer
Dim sExe As String
Const q As String = """"
On Error GoTo Err_Handler
DoCmd.Hourglass True
sLocalFLD = "C:\" 'or the name of the local folder, where you want
the file
' will break if empty folder exist so error to pass
' must create folder first, so API calls work
On Error Resume Next
If Dir(sLocalFLD & "\") = "" Then MkDir (sLocalFLD)
On Error GoTo Err_Handler
sScrFile = sLocalFLD & "\download.scr"
If Dir(sScrFile) <> "" Then Kill sScrFile
sTarget = q & sLocalFLD & sFile & q
sFile = q & sFile & q
' Open a new text file to hold the FTP script and load it with
' the appropriate commands. (Thanks Dev Ashish !!!)
iFile = FreeFile
Open sScrFile For Output As iFile
Print #iFile, "open " & sSVR
Print #iFile, sUID
Print #iFile, sPWD
Print #iFile, "cd " & sFLD
Print #iFile, "binary"
Print #iFile, "lcd " & q & sLocalFLD & q
Print #iFile, "get " & sFile & " " & sTarget
Print #iFile, "bye"
Close #iFile
sExe = Environ$("COMSPEC")
sExe = Left$(sExe, Len(sExe) - Len(Dir(sExe)))
sExe = sExe & "ftp.exe -s:" & q & sScrFile & q
ShellWait sExe, vbHide
DoEvents
Exit_Here:
DownloadFTPFile = GetFileText(sScrFile
)
DoCmd.Hourglass False
Exit Function
Err_Handler:
MsgBox Err.Description, vbExclamation, "E R R O R"
Resume Exit_Here
End Function
Jesper Fjølner, Denmark
| |
| Jesper Fjølner 2005-10-27, 8:31 am |
| > Is their a way to get the Internet explorer proxy settings using VBA?
> Is their a better way than using the WinHttpRequest objects?
Hi Luke,
Is the WinHttpRequest working for you?
I pretty much have my ftp-solution working and can send you some code if you
need it.
Jesper Fjølner
|
|
|
|
|