Question Weather Forecasting Pictures

Paulcliman

Registered User.
Local time
Today, 08:31
Joined
Mar 29, 2009
Messages
23
I have a very simple Access2003 database keeping weather records.
I have a table "weather" with all forecasts & results.
I have a lookup table "forecasts" which gives me a combobox e.g. sunny, mainly cloudy, cloudy, snow, etc.
I have a table "pictures" with small images (BMP) which correspond to the forecasts in the previous table.
How can I get the appropriate picture to appear on a form when I select a forecast ? - e.g. on selecting "sunny" from the conbo box, I would like the "sunny" image to appear. Do I need a bound image box, do I need code ? I DO need lots of help :confused:

Maybe I'm even approaching this from the wrong direction??

Thank you in anticipation ......
PC
 
WOW! First, many thanks for such a speedy response to my problem; much appreciated.
O.K. - on the form my combo box is called "forecast_day" and my bound object box is called "OLEbound36"
I clicked on the form's combo box and in the expression builder I pasted this code:
If Me.forecast_day.Value = "sunny" Then
Me.OLEbound36.Picture = "D:\XYZ\Weather_images\sunny.bmp"
Else
If Me.forecast_day.Value = "sultry_night" Then
Me.OLEbound36.Picture = "D:\XYZ\Weather_images\sultry_night.bmp"
Else
If Me.forecast_day.Value = "Sultry" Then
Me.OLEbound36.Picture = "D:\XYZ\Weather_images\sultry.bmp"
Else
If Me.forecast_day.Value = "snow_night" Then
Me.OLEbound36.Picture = "D:\XYZ\Weather_images\snow_night.bmp"
Else
If Me.forecast_day.Value = "snow" Then
Me.OLEbound36.Picture = "D:\XYZ\Weather_images\snow.bmp"
Else
If Me.forecast_day.Value = "sleet" Then
Me.OLEbound36.Picture = "D:\XYZ\Weather_images\sleet.bmp"
Else
If Me.forecast_day.Value = "showers" Then
Me.OLEbound36.Picture = "D:\XYZ\Weather_images\showers.bmp"
Else
If Me.forecast_day.Value = "mainlycloudy_night" Then
Me.OLEbound36.Picture = "D:\XYZ\Weather_images\mainlycloudy_night.bmp"
Else
If Me.forecast_day.Value = "mainlycloudy" Then
Me.OLEbound36.Picture = "D:\XYZ\Weather_images\mainlycloudy.bmp"
Else
If Me.forecast_day.Value = "heavy_rain" Then
Me.OLEbound36.Picture = "D:\XYZ\Weather_images\heavy_rain.bmp"
Else
If Me.forecast_day.Value = "foggy_night" Then
Me.OLEbound36.Picture = "D:\XYZ\Weather_images\foggy_night.bmp"
Else
If Me.forecast_day.Value = "foggy" Then
Me.OLEbound36.Picture = "D:\XYZ\Weather_images\foggy.bmp"
Else
If Me.forecast_day.Value = "deluge" Then
Me.OLEbound36.Picture = "D:\XYZ\Weather_images\deluge.bmp"
Else
If Me.forecast_day.Value = "cloudy" Then
Me.OLEbound36.Picture = "D:\XYZ\Weather_images\cloudy.bmp"
Else
If Me.forecast_day.Value = "clear" Then
Me.OLEbound36.Picture = "D:\XYZ\Weather_images\clear.bmp"
End If

Goes on a bit, doesn't it? Anyway, it didn't work - I get an error message saying it cannot find the macro If.Me
Any other advice as to what I'm doing wrong ?
PC
 
......... actually, just checking, should "If" really be "Iif" ?
Remeber, I'm a raw beginner but just spotted this word as I was working with that expression builder
 
The error mssage you are getting is not compaible with the code you have posted.Some where in your code you must have "If.me" which Access is interpreting as a macro. When you get the error it should highlight the faulty line.

TRy amending your code as follows and see what happens
Code:
If Me.forecast_day.Value = "sunny" Then
  Me.OLEbound36.Picture = "D:\XYZ\Weather_images\sunny.bmp"
Elseif  Me.forecast_day.Value = "sultry_night" Then
  Me.OLEbound36.Picture = "D:\XYZ\Weather_images\sultry_night.bmp"
ElseIf Me.forecast_day.Value = "Sultry" Then
  Me.OLEbound36.Picture = "D:\XYZ\Weather_images\sultry.bmp"
ElseIf Me.forecast_day.Value = "snow_night" Then
  Me.OLEbound36.Picture = "D:\XYZ\Weather_images\snow_night.bmp"
ElseIf Me.forecast_day.Value = "snow" Then
  Me.OLEbound36.Picture = "D:\XYZ\Weather_images\snow.bmp"
ElseIf Me.forecast_day.Value = "sleet" Then
  Me.OLEbound36.Picture = "D:\XYZ\Weather_images\sleet.bmp"
ElseIf Me.forecast_day.Value = "showers" Then
  Me.OLEbound36.Picture = "D:\XYZ\Weather_images\showers.bmp"
ElseIf Me.forecast_day.Value = "mainlycloudy_night" Then
  Me.OLEbound36.Picture = "D:\XYZ\Weather_images\mainlycloudy_night.bmp"
ElseIf Me.forecast_day.Value = "mainlycloudy" Then
  Me.OLEbound36.Picture = "D:\XYZ\Weather_images\mainlycloudy.bmp"
ElseIf Me.forecast_day.Value = "heavy_rain" Then
  Me.OLEbound36.Picture = "D:\XYZ\Weather_images\heavy_rain.bmp"
ElseIf Me.forecast_day.Value = "foggy_night" Then
  Me.OLEbound36.Picture = "D:\XYZ\Weather_images\foggy_night.bmp"
ElseIf Me.forecast_day.Value = "foggy" Then
  Me.OLEbound36.Picture = "D:\XYZ\Weather_images\foggy.bmp"
ElseIf Me.forecast_day.Value = "deluge" Then
  Me.OLEbound36.Picture = "D:\XYZ\Weather_images\deluge.bmp"
ElseIf Me.forecast_day.Value = "cloudy" Then
  Me.OLEbound36.Picture = "D:\XYZ\Weather_images\cloudy.bmp"
ElseIf Me.forecast_day.Value = "clear" Then
  Me.OLEbound36.Picture = "D:\XYZ\Weather_images\clear.bmp"
End If
 
Last edited:
Again, thank you for all your time & effort in responding so quickly.
I have copied and pasted your code into the "on change" box of the properties of my "forecast.day" combo box ............. and get exactly the same error message !
Beginning slowly to despair !
Any other way of doing this ?
PC
 
Which line is Erroring. If the error message is referring to if.me then search your code to see if you have a typo with if.me in it.
 
Rebonjour !
I have copied & pasted your suggestion code and receive the following error message:
<< Microsoft Office Access can't find the macro 'If me'
The macro (or its macro group) doesn't exist, or the macro is new but hasn't been saved.
Note that when you enter the macrogroupname.macroname syntax in an argument, you must specify the name the macro's macro group was last saved under. >>

This obviously means absolutely NOTHING to me.
I have inadvertently misled you, sorry. It never was 'If.Me' it has always been 'If Me'
 
Last edited:
Can you post your DB so I can see what is acually happening
 
I would be overjoyed for you to look at it (such as it is !) Can you tell me how and where to do such a thing ?
Do you read French or shall I make a copy in English ? No problem for that.
Paul
 
When putting code into an event you first need to select "Event Procedure and then click on the ... at the right hand end. This will open the VBA editor with an empty sub set up. Paste your code in that.

See the attached DB to see how it should be done.
 

Attachments

A better solution which is more manageable with less code is to create a new table that has fields in it

Weather condition and bitmapPath

When the user selects a weather condition your code looks up the bitmap path in your table for the location of the bitmap.

Eg

Code:
Sub ComboBox AfterUpdate()

Dim StrPath As String
   StrPath = DLookup("BitmapPath","TblBitmaps","WeatherCondtion='" & Me.ComboBox & "'")


Next check to see if the file actually exists in the specified location

If Dir(StrPath) <> "" then
   Me.OlePicture.Picture = StrPath
Else
   MsgBox "No Matching Image Found in Location",vbExclamation+VbOkOnly,"Missing Image"

End If

End Sub

This code is aircode and as such is untested. Don't forget to change the field and table names to match the ones you have.

David
 
Thanks again for your responses.
Rabbie - I started afresh and followed your instructions and example. However, it still doesn't work. When I try to select a weather condition, the debugger pops up and a line is highlighted in yellow
Me.OLEBound36.Picture = "D:\XYZ\Weather_images\sultry.bmp"
as if it cannot follow the filepath. Another possibility, I think, is that I am not constructing the OLEboundbox properly?
Would it be too presumptuous for me to attach this latest poor attempt for you to see ? I'll attach it anyway, you'll ignore it no doubt if you haven't time or interest!!

Hello DCrake - thank you for the code, but I confess I have neither the knowledge nor the skill to know where to put this code or even how to change it for my own settings!
I REALLY do appreciate what you people are doing on this forum & I apologise for being such a crétin
 

Attachments

I think you are going about this the wrong way. In the code you provided, you used paths to the images, but in the BitmapPath field of your table, you instead provided the picture as an OLE object. You are also having issues with the Picture function because it doesn't apply to OLE objects, only linked Image objects. I also recommend you provide a full network path to the picture files if D is a mapped network drive, in case other users do not have the same drive mapped to D.

See if the attached solution works for you. I only fixed the day portion, so you'll have to change the night portion. The OLE object on the table was changed to text with a path to the file instead of the actual picture, which you'll have to change to the correct path for your files. The OLE object on the form has been replaced by an Image control. I then used DCrake's code above because of the error handling in place in case the file does not exist or cannot be found at the path specified. Again, you'll have to recreate the night portion to match these circumstances, but this worked perfectly for me with all files located on C:\.
 

Attachments

Hello again
Thank you for the help. I fear my ignorance gets me deeper & deeper into trouble. I have made all the changes you mentioned
2 tables now changed to a text (bitmap path) rather than OLE package.
Changed the OLE bound boxes to Image boxes.
I have added your code to my "day forecast, copied it into my "night" forecast with the necessary alterations (I hope).
The result is that now NOTHING works. I am even unable to change or add any other data !
Have you the time to look again at my DB and see if you can explain to me what stupid thing I have done now ?
 

Attachments

I may be being over-simplistic but can't you just create a bound object frame with a dlookup formula in it to pull in the required image based on the value selected from the drop-down list?

I have tested this for the night forecast ...

e.g. =DLookUp("[bitmapPath]","[tblforecast_night]"," [forecast_night] = [tblforecast_night]![weather condition] ")

I note however that your table [tblforecast_night] doesn't actually have the images in it, just a file/directory path. So I suggest changing field [bitmapPath] from Text to OLE Object and paste the images in using an input form based on the table?
 
Last edited:
An amended database is attached ...

I think from this point all you have to do is
1) amend the table structures as advised above (text to OLE object)
2) create simple continuous form(s) to capture the ACTUAL images you wish to store in the amended tables

Once the drop-down list selection is made you may need a refresh command or to press the F9 key to bring the correct image up.
 

Attachments

Here is a partial solution for you.

Take a look at the following and see if you can work out what I have done. This will enable you to replicate the night time.

forms OnCurrent Event

Daytime image control
forcast day combo box

Query
Weather Table


David
 

Attachments

Here is a partial solution for you.

Take a look at the following and see if you can work out what I have done. This will enable you to replicate the night time.
forms OnCurrent Event (OH DEAR !)
Daytime image control (GOT IT!)
forcast day combo box (GOT IT !)
Query (GOT IT !)
Weather Table (GOT IT !)

David

I am guessing you are / used to be a teacher ! Thank you for making me work; however, I have done everything (I think) except the OnCurrent Event.
First I tried replicating it and using all the "night" references, but it didn't like the fact that there were now TWO identical events.
Then I tried to add the "night" code at the end of the existing Event procedure, but it didn't like that either.
I think I might be missing a command word like AND or OR or something in order to add the "night" code to this procedure ?
P - L - E - A - S - E tell me I'm nearly there ? here is the very latest version showing what I've done so far...
 

Attachments

Users who are viewing this thread

Back
Top Bottom