我有一个MS Access应用程序,在表单上有一个按钮,应该移动文件,更新记录的字段并打开包含以下参数的网页: 1)访问记录的ID 2)更新字段的值3)密码字。
除了打开网页外,一切正常。
我发布了这篇文章:How to open a URL from MS Access with parameters并撰写了一行CreateObject(" Shell.Application")......
FSO.MoveFolder FLD_READY & "\" & rs.Fields(order_int_ID), FLD_SERVER & "\" & rs.Fields(order_int_ID)
rs.Edit: rs.Fields(order_stage) = os07: rs.Update
CountFile = CountFile + 1
CreateObject("Shell.Application").Open "https://example.com/status/" & "/" & rs.Fields(order_int_ID) & "/" & 'os07' & "/" & 'secretword'
请告诉你 - 它有什么问题?我应该如何更改它以使其正常工作?
这是整个脚本。提到的块几乎就在最后。
' Order_stage status
Private Const os06 = "06"
Private Const os07 = "07"
' Transfer to server
Private Const FTP_TRANSFER_TYPE_UNKNOWN As Long = 0
Private Const INTERNET_FLAG_RELOAD As Long = &H80000000
Private Const FORMAT_MESSAGE_FROM_HMODULE = &H800
Private szErrorMessage As String
Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Const FTP_TRANSFER_TYPE_ASCII = &H1
Private dwType As Long
Private Const FtpConnectionFile = "D:\ftp_connection.txt"
Private Const FTP_UP_HOME = "public_html/"
'Folders
Private Const FLD_READY = "d:\10-5-0-Ready"
Private Const FLD_SERVER = "d:\10-6-0-Server"
Private Sub Ctl10_50___SERVER_Click()
Dim ftpHost As String
Dim ftpPort As Long
Dim ftpUser As String
Dim ftpPassword As String
Dim CountFile As Integer
Dim hOpen As Long
Dim hConn As Long
Dim hPut As Long
Dim ftpCurrentDirectory As String
Dim szDir As String
Dim strTextLine As String
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim oFolder As Object
Dim oSubFolder As Object
Dim oFile As Object
Dim strFileExt As String
Dim Strt As Integer
Dim i As Integer: i = 0
Dim iFile As Integer: iFile = FreeFile
Open FtpConnectionFile For Input As #iFile
Do Until EOF(1)
Line Input #1, strTextLine
Select Case i
Case Is = 0: ftpHost = Trim(strTextLine)
Case Is = 1: ftpPort = CLng(Trim(strTextLine))
Case Is = 2: ftpUser = Trim(strTextLine)
Case Is = 3: ftpPassword = Trim(strTextLine)
Case Is = 4: Exit Do
End Select
i = i + 1
Loop
Close #iFile
hOpen = InternetOpenA("FTP Client", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
If hOpen = 0 Then
ErrorOut Err.LastDllError, "InternetOpen"
End If
dwType = FTP_TRANSFER_TYPE_ASCII
hConn = InternetConnectA(hOpen, ftpHost, ftpPort, ftpUser, ftpPassword, 1, 0, 0)
If hConn = 0 Then
ErrorOut Err.LastDllError, "InternetConnect"
End If
If (FtpCreateDirectory(hConn, FTP_UP_HOME) = False) Then
ErrorOut Err.LastDllError, "FtpCreateDirectory"
Else
End If
If (FtpSetCurrentDirectory(hConn, FTP_UP_HOME) = False) Then
ErrorOut Err.LastDllError, "FtpCreateDirectory"
Else
End If
For Each oFolder In FSO.GetFolder(FLD_CHECK).SubFolders
For Each oFile In oFolder.Files
strFileExt = FSO.GetExtensionName(oFile)
'MsgBox (strFileExt)
If strFileExt = "psd2" Then
Dim rs2 As Recordset
Set rs2 = CurrentDb.OpenRecordset("SELECT A_INCOMING_ORDERS.order_int_ID, A_INCOMING_ORDERS.order_stage FROM A_INCOMING_ORDERS WHERE (A_INCOMING_ORDERS.order_int_ID = '" & oFolder.Name & "')")
Do While Not rs2.EOF
rs2.Edit: rs2.Fields(order_stage) = os40: rs2.Update
rs2.MoveNext
Loop
rs2.Close
FSO.MoveFolder oFolder.Path, FLD_ALTER & "\" & oFolder.Name
End If
Next
Next
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("SELECT A_INCOMING_ORDERS.order_int_ID, A_INCOMING_ORDERS.order_stage FROM A_INCOMING_ORDERS WHERE (A_INCOMING_ORDERS.order_stage = '" & os06 & "');")
CountFile = 0
Do While Not rs.EOF
If (FSO.FolderExists(FLD_READY & "/" & rs.Fields(order_int_ID))) Then
If (FtpCreateDirectory(hConn, rs.Fields(order_int_ID)) = False) Then
ErrorOut Err.LastDllError, "FtpCreateDirectory"
Else
End If
For Each oFile In FSO.GetFolder(FLD_READY & "/" & rs.Fields(order_int_ID)).Files
hPut = FtpPutFileA(hConn, FLD_READY & "/" & rs.Fields(order_int_ID) & "/" & oFile.Name, "/" & FTP_UP_HOME & "/" & rs.Fields(order_int_ID) & "/" & oFile.Name, 2, 0)
If hPut = 0 Then
ErrorOut Err.LastDllError, "FtpPutFileA"
Else
End If
Next
FSO.MoveFolder FLD_READY & "\" & rs.Fields(order_int_ID), FLD_SERVER & "\" & rs.Fields(order_int_ID)
rs.Edit: rs.Fields(order_stage) = os07: rs.Update
CountFile = CountFile + 1
CreateObject("Shell.Application").Open "https://example.com/status/" & "/" & rs.Fields(order_int_ID) & "/" & 'os07' & "/" & 'secretword'
End If
rs.MoveNext
Loop
rs.Close
InternetCloseHandle hConn
InternetCloseHandle hOpen
MsgBox "Count: " & CountFile
End Sub
答案 0 :(得分:0)
通过将文字文本与变量和常量连接来构造字符串:
CreateObject("Shell.Application").Open "https://example.com/status/%7" & rs.Fields(order_int_ID) & "%7D/%7B" & os07 & "%7D/secretword"
我没有看到名为secretword
的声明变量或常量,因此不是 secretword 键入您的实际密码字。
以上构建基于您已删除的评论中的示例。该示例不在问题中,因此如果不需要任何文字字符,则删除它们。
答案 1 :(得分:0)
这个问题的答案是:
Application.FollowHyperlink "https://example.com/status/" & rs.Fields(order_int_ID) & "/" & "os07" & "/" & "secretword", , True
此解决方案适合我。