How To Display PDFs In A Form

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone and welcome to programming in Access 2013 my name is Steve Bishop today's video is a how-to video and this particular topic is very common requests that I get from not only my youtube channel but also from some of the forums that I frequent and this particular question comes from Katey sin Lau and he asks can you show me how to display PDF files in an access forum and that's a very good question a lot of times what we want to do is display the contents of a file to our users actually within a forum and luckily for us there is a special component there's a special control that we can put on our forms that allows us to display just about any type of file including PDF files and I'm going to show you the method of how you can do that today alright so let's go ahead and back out and go into our database and the first thing I'm going to do is going to go to the create tab and I'm going to create a new form and I'm going to go right into the design of the form I'm not going to do a wizard or anything now I'm going to make this nice and large because we're going to be displaying the entire contents of a phial and you probably want to make sure also that you making it large individuals that that the application may have because what's going to happen is when you open up a file inside of access access is not actually the application that's opening the file instead the default program the default application that is used to view that file will open up a window inside of your form so especially with PDF files you need to make sure that the user has some sort of PDF viewer application like Adobe Reader or Foxit reader which is I use Foxit reader for my PDFs so what we're going to do is we're going to first and foremost make sure that our form is nice and big it's got to be large enough so that the user can see everything on here and I'm going to go ahead and drop in a text box and this will become very important later I'm going to go ahead and name this text box or I'm going to give it a label here of file location okay and I'm going to move this over a little bit just make sure it's the right size and make that nice and wide here because this is actually going to display the full location on our computer where that file is that we are displaying to the user I'm also going to drop in a button here because what we're going to do is we're going to make this a nice dynamic and interactive form that allows the user to select a file and then display that file inside of our form so I'm going to go ahead and make this just say browse and finally the control that we're actually going to display the content in is the web browser control okay and that may sound like a little bit of a weird thing I don't really want to display something from the web on here but actually the web browser is a very very dynamic control that allows us to view pretty much any type of file both a web address or a location on our computer now before I get to this dialog box I'm going to go and cancel this for just for a moment what I need to do is I need to put some names on all of these controls so I'm going to go ahead and name my text box txt file location and then I'm going to make this browse button I'm going to change it to button browse and finally this web browser I'm just going to go ahead and call it let's say WB contents whatever you feel like naming it's perfectly fine this is just what I'm going with all right let me make this a little bit wider here just want to make sure it's fully viewable and a little taller okay all right so we've got all the controls I'm going to go ahead and minimum make this nice and big so I can see the whole screen here now what we're going to do is since we've got the text box named txt file location I'm going to go back into the data tab of my web of my web browser and I'm going to go to the control source and click on the ellipsis and we're going to get that insert hyperlink dialog box back open now here where it says Bay URL we can click on this ellipsis button and this will give us our expression builder and on our expression builder we can actually select the text box called txt file location that we created and I'm just going to go ahead and double click that and you'll see it just plops it right in there as the expression and I'm going to go ahead and click OK so now what's actually happening here is that the contents of the control the control source are actually directly linked to whatever we put up here in our file location text box okay so we're going to go ahead and click OK on that and now what we're going to do is we're going to set we're going to do some of the code on our browser button to make the contents of our text box to change the file location basically alright so let's go ahead and go to the on click event for our browse button and go to the code builder and the first thing I always do is I want to make sure option explicit is set up here just so that in case I ever fat-finger a variable or something that it'll tell me all right now the first thing that we want to do is since we want this to display some sort of file you know display a dialog to the user for the file location we're going to go ahead and create a file variable as a file lips file dialog now you may get a prompt that you need to add a particular reference and that's perfectly fine that'll probably just prompt you in Access 2013 it'll just prompt you for the particular type of reference that you need and I can't remember which one it is off the top of my head but I believe it is this Microsoft Office object library I'm not entirely sure but you will get prompted for it and just make sure that you go ahead and add that reference ok so now that we've got our file variable declared here I'm going to go ahead and set oops set file equal to application file dialog and in parentheses we do MS OH file dialog picker okay and that is a particular a very special type of file dialog that allows us to to pick a particular file and then return the results from that dialog so let's go ahead and do that and actually take out some of that some of that extra space there okay so now that we've set that let's go ahead and make sure that file allow multi-select is false because we don't want to allow the user to pick more than one particular file now let's go ahead and do Phi if file show and if the user doesn't select a file this will return false so we can just say that you know it's going to make sure that show is going to return true if so if they did actually pick a file so we can say if file dot show is true then and I'm just going to do my end if statement here ahead of time and we're going to go ahead and set me txt file location equal to file selected items and item in parentheses it's the first one just make sure this is a collection it is not a array so one is actually the first value that the user selects okay and really that's pretty much it that's all that we really need to do we just need to change the file location based upon what the user has selected from the file dialog and if they of course select no file then it's just going to go ahead and skip the assignment and end our sub so we're good there let's go ahead and save it and it looks like it needs us to save the form I'm going to go ahead and call it form PDF display or actually form file display let's call it that okay so just make sure okay and then we'll hit the debug I want to compile it just make sure I didn't make any errors that looks good all right now I think we're actually ready to go so let's go ahead and save it one more time let's go ahead and view the form and right now since there's nothing up here in our text box we're getting on the address is not valid you could set a default value up here in the text box if you really wanted to but I'm not too worried about that I'm just going to go ahead and click on the Browse button and there's our dialogue window if I click on the NFL football we see the dot jpg I'm going to go and click OK and voila it automatically does the refreshing and everything and updates the image that is displayed in our web browser control let me go ahead and change this over to a PDF because that was what specifically was requested and I have a PDF file here under test there's my report dot 1 report 1 PDF I'm going to go and click OK and you'll see it'll take some time here but this is the Foxit viewer opening up as a window inside of my form and I can go ahead and do all of the controls that are available to me for for Foxit and I think I can even expand this out yeah I can make it the full screen here so or I can have the controls up there so and I can of course hit the save or the print or email all of the controls that Fox it provides for me are open inside of this window alright so there you go that is how you can design a form that opens up a particular type of file and displays it to the user in your form
Info
Channel: Programming Made EZ
Views: 124,130
Rating: 4.927711 out of 5
Keywords: Microsoft, Access, 2013, Programming, VBA, Visual Basic, Applications, tutorial, lesson, guide, database, SQL, beginner, advanced, software, microsoft access, table, query, form, code, coding, development, visual basic for appliations, computer programming, How-to (Media Genre), PDF/A (File Format), controls, web browser, Portable Document Format (File Format), Hypertext Transfer Protocol (Internet Protocol)
Id: KeyoRBTAa9I
Channel Id: undefined
Length: 10min 4sec (604 seconds)
Published: Sun Jun 15 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.