MS Access VBA: how do I clear Image control? - image

I have an Image control that reads a file from disk as the user navigates. If there is no file (an empty field), I need to erase the previous image. The microsoft page says to do as follows:
Sub Form_Click ()
picture1.picture = LoadPicture()
End Sub
But when I do it, Access complains that "the argument is not optional"! I also tried LoadPicture("") as stated here and here, to no avail. It says "Microsoft Access can't open the file '0'." How can I clear the picture in runtime? I'm using Access 2002. Thanks in advance!

Use the following:
picture1.picture = ""

Related

How to clear an Image in a Userform?

I have a Userform in which I use an Image control. I display a picture in this control, based on two criteria.
I don't know how to clear this Image in the Userform when I want to type two new criteria.
You can easily 'clear' your UserForm Image control (e.g. Image1) via Image1.Picture = LoadPicture(vbNullString). In the example below you would switch between showing a defined picture and displaying the empty control when clicking your command button. In order to control the Image status (empty or not) you check the image picture property via If Image1.Picture Is Nothing Then...
Code example in userform module (Excel)
Option Explicit
Private Sub CommandButton1_Click()
' Purpose: Change view between given image and no image
Dim sImgName As String ' picture name string
sImgName = "C:\Temp\MyPicture.gif"" ' <<< choose your picture name"
With Me.Image1
If .Picture Is Nothing Then ' picture property has been cleared already
.Picture = LoadPicture(sImgName)
Else ' a picture is already displayed
.Picture = LoadPicture(vbNullString) ' clear it now
End If
End With
End Sub
Hint to use in MS Access
Note the different use in MS Access repeating #DrMarbuse 's comment as late edit:
In Access 2010, the picture is directly set by the image path. So LoadPicture() shall not be used anymore (In Excel it is required). Everything stayed the same and worked like a charm.

How do I trap an error when OneDrive image renders file.OpenAsync error

In a project I try to give users the option to select images from their personal libraries. Nothing special as such.
This goes perfectly when the user selects the desired image from a local imagelibrary. But when images are selected from OneDrive, an error occurs, and I'm not able to trap the error. The source of the error seems to be in the file.OpenAsync method.
It seems like there may be a relation with the size of the selected image, but I cannot tell, as i'm not able to catch the error.
Here's the codesnippet (it's taken from the XAML image SDK samples in fact)
Dim picker As New FileOpenPicker With {.ViewMode = PickerViewMode.Thumbnail, .SuggestedStartLocation = PickerLocationId.PicturesLibrary}
'picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary
picker.FileTypeFilter.Add(".png")
picker.FileTypeFilter.Add(".jpeg")
picker.FileTypeFilter.Add(".jpg")
picker.FileTypeFilter.Add(".bmp")
Dim wBitMap as new WritableBitmap(200,200)
Dim file As StorageFile = Await picker.PickSingleFileAsync()
' Ensure a file was selected
If file IsNot Nothing Then
Try ' Set the source of the WriteableBitmap to the image stream
Using fileStream As IRandomAccessStream = Await file.OpenAsync(Windows.Storage.FileAccessMode.Read)
Await wBitmap.SetSourceAsync(fileStream)
wBitmap.Invalidate()
vwImage.Source = wBitmap
End Using
Catch e1 As TaskCanceledException
' The async action to set the WriteableBitmap's source may be canceled if the user clicks the button repeatedly
End Try
End If
As you can see, there is a try-catch in place, but nonetheless a non-trapped error pops up, and stepping through, I can detect that it happens in the line
Await file.OpenAsync(Windows.Storage.FileAccessMode.Read)
Now my question is: how do I catch this error? Am I right that the line above is the source of the error? And if not so: what is and how to overcome?
After a lot of experimenting, I think I found the solutoion.
When a StorgeFile is selected to be used as the source for an image, it is wise to check the StorageFile.Attributes.
Files that are selected will carry an Attributes value. In the case of a file from OneDrive, the Attributes value was 544 (the value that you get when combining Archive and LocallyIncomplete. So that file has to be downloaded first, and then it will be available to use.
This is explained here:
Link to the MSDN documentation on StorageFile.Attributes

VBS - display multple filetypes in save dialog

I got the following code to open the save dialog with one FileType:
Set objDialog = CreateObject("SAFRCFileDlg.FileSave")
objDialog.FileName = "Automatic Generated Presentation"
objDialog.FileType = "PowerPoint 97-2003 Presentation (*.ppt)"
objDialog.OpenFileSaveDlg
How can I add another FileType to the combobox / listbox in the dialog?
I tried to seperate them using '|', using ',', using ';' and more - nothing worked ofcourse.
Is that even possible?
I didnt find anything like that in the internet.
Will appreciate your help.
I've found an interesting article where the author debugs Windows API calls made by the SAFRCFileDlg.FileSave object to find out whether it allows multiple file filters:
Debugging the SAFRCDLG.DLL FileType filter string
The answer is No.

How to type cast webbrowsercontrolobj.document to mshtml.HTMLDocument VB6? or How to submit form loaded in webbrowser control in vb6?

Hello I am writing code in VB6 only (no VB.NET)
I have webbrowsercontrol object named webbrowser1
I have added reference of microsoft html object library in project.
I am trying this line but is giving error.
Dim doc as MSHTML.HTMLDocument
doc = DirectCast(webbrowser1.document, MSHTML.HTMLDocument)
line 2 is giving error that no method or data found at MSHTML.HTMLDocument
Please help me solving this problem.
What I want is I have one webpage having 2 (html forms) in it. I am loading that page into
webbrowser control by,
webbrowser1.navigate "url"
I have mapped event to handle html button click in webbrowser1's document.
When user clicks on this button I want to submit second form of html page.
Is there any other way to do it?
I also tried following code
'this line is working properly
'this is the code to submit first form in html page
webbrowser1.document.Forms(0).submit
but when I do
'this line is giving error though there are 2 forms available in html page
webbrowser1.document.Forms(1).submit
So ultimate goal is to submit second form of html document.
Please show me right direction.
You need to change Dim doc as MSHTML.HTMLDocument to Dim doc as MSHTML.IHTMLDocument.
Notice the IHTMLDocument has an I at the start, then try to submit the form.
Also, there is no such thing as DirectCast in VB6 - that is only a VB.NET thing.
So just do this:
Dim doc as MSHTML.IHTMLDocument
Set doc = webbrowser1.document
Now you will get intellisense on doc. :)
Let me know how it goes.
Have you tried just direct assignment?
Dim doc as MSHTML.HTMLDocument
Set doc = webbrowser1.document
VB6 doesn't really do casting, but you can access any method (early bound) by assigning it to an variable of the required type, or (late bound) by blindly using a variable of Object type.

vb6 Capture Entire Web Page

Hey all, I've been trying to find the code that allowed me to capture an entire web page using the webbrowser1 control and i believe also a picturebox or 2.. but i am not able to find the code that i used a couple months ago! I've been goodgling until I'm all googled out!
If anyone knows of the code for VB6 then please post a link to it!.
Thanks,
David
Do you mean the HTML source? If so you can add a reference to the Microsoft HTML obj Library and;
Dim doc As MSHTML.HTMLDocument
set doc = YourWebBrowserCtrl.Document
msgbox doc.documentElement.outerHTML
However this will not return the exact source as at this point its been parsed by IE. (It also won't include doc type or anything else preceding the opening <html> tag.
If you do want the source, add an internet transfer control and just call .openURL to get the full content.
Dim DrawSize As New Size(1024, 768)
Using MyBrowser As New WebBrowser
MyBrowser.ScrollBarsEnabled = False
MyBrowser.Size = DrawSize
MyBrowser.Navigate("http://www.stackoverflow.com")
While MyBrowser.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
End While
Using myBitmap As New Bitmap(DrawSize.Width, DrawSize.Height)
MyBrowser.DrawToBitmap(myBitmap, New Rectangle(New Point(0, 0), DrawSize))
myBitmap.Save("C:\test.jpeg")
End Using
End Using

Resources