Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
682 views
in Technique[技术] by (71.8m points)

vba - How to open a URL from MS Access with parameters

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.

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

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.

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.

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Application.FollowHyperlink is fickle.

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

or

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

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


If the URL is in a string variable, you may need to cast it to Variant, because that's what Shell.Application.Open expects:

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

see https://stackoverflow.com/a/56173911/3820271, thanks Toby and Anthony for pointing this out!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...