vba 如何使用参数从 MS Access 打开 URL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40462176/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 11:29:28  来源:igfitidea点击:

How to open a URL from MS Access with parameters

vbams-accessurl

提问by Mark Cross

I have a basic MS Access application that has a button on a form that should open a webpage with the ID of the Access record as the parameter, but everything I have tried results either in an error by Access or only the base URL opening in the web page.

我有一个基本的 MS Access 应用程序,它在表单上有一个按钮,该按钮应该打开一个以 Access 记录的 ID 作为参数的网页,但是我尝试的所有内容要么导致 Access 出错,要么仅导致基本 URL 在网页。

I have tried adding VBA to the button's click event as so:

我尝试将 VBA 添加到按钮的点击事件中,如下所示:

Application.FollowHyperlink _ 
"http://example.com/index.php?r=controller/action&id=" & Me.ID 

but all I get is the base URL opening on the web browser (ie http://example.com). If I remove the '?' and the '&' from the full URL the button will open the browser with the full URL minus the '?' and the '&', which of course errors the page.

但我得到的只是在网络浏览器上打开的基本 URL(即http://example.com)。如果我删除“?” 和来自完整 URL 的“&”按钮将打开带有完整 URL 减去“?”的浏览器 和“&”,这当然会使页面出错。

I have tried setting a hyperlink control's property as:

我尝试将超链接控件的属性设置为:

="http://example.com/index.php?r=controller/action&id=" & Me.ID

but it does the same thing as noted above.

但它的作用与上述相同。

I have tried creating a Macro with the same results. I have tried using the Hyperlink Builder and using [formName]![id]as the parameter but same thing happens or Access errors.

我尝试创建一个具有相同结果的宏。我曾尝试使用 Hyperlink Builder 并[formName]![id]用作参数,但同样的事情发生或访问错误。

I have read this article: https://msdn.microsoft.com/en-us/library/office/ff822080.aspxand tried adding the part in the URl after 'index.php/ to the ExtraInfo place in the code, but same thing.

我已经阅读了这篇文章:https: //msdn.microsoft.com/en-us/library/office/ff822080.aspx 并尝试将 'index.php/ 之后的 URl 部分添加到代码中的 ExtraInfo 位置,但是一样。

Help! It can't be that hard to simply have Access open a URL with a parameter on the end of the URL.

帮助!简单地让 Access 打开一个在 URL 末尾带有参数的 URL 并不难。

回答by Andre

Application.FollowHyperlinkis fickle.

Application.FollowHyperlink善变。

Use either ShellExecute:
Open an html page in default browser with VBA?

使用以下任一方法ShellExecute
使用 VBA 在默认浏览器中打开 html 页面?

or

或者

CreateObject("Shell.Application").Open "http://example.com/index.php?r=controller/action&id=" & Me.ID 

see https://stackoverflow.com/a/18922262/3820271

https://stackoverflow.com/a/18922262/3820271

回答by Toby Ovod-Everett

Note that if you are having issues with CreateObject("Shell.Application").Opennot working with a variable, it might be a casting issue - try tossing a CVar()around the parameter. See https://stackoverflow.com/a/56173911/8512931for more details.

请注意,如果您在CreateObject("Shell.Application").Open不使用变量时遇到问题,则可能是强制转换问题 - 尝试CVar()在参数周围扔一个。有关更多详细信息,请参阅https://stackoverflow.com/a/56173911/8512931