Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Picture hot spot 3

Status
Not open for further replies.

JanTore

Technical User
Jun 9, 2001
34
NO
Hi,
I'm trying to load a dataform from another form using "hotspots" on an image. The question is how can i bind the hot spots to a database record?

The picture is a map over a country and the hotspots are cities, and by clicking on a city it loads the dataform which has information on that city. The dataform is using ADO to connect to a Access database.

Any ideas? I'm lost..

Jan Tore
 
just a thought... you could used labels that are invisible.. over it or.. like on the mouse down area use the x and y things :/ sorry im so umm vague :/ haha you said idea so im throwing one out hehe... but use those to have it check if it is between such and such mark it when pressed it will activate what you want... i dunno i could probably do the coding.. but just got on these boards and im half alseep... i hope my "idea" helps.. :/ sorry
 
Yes thats what I was planning to do, but the problem is to bind the labels to the database. Ive been trying this:

Label1 select Id from Citys where Id LIKE "001"
Label2 select Id from Citys where Id LIKE "002"

and so on for each hotspot..

then I'm facing my other problem, how to open the form2 and retrive the other fields that belongs to "Id 001"

I tried "select * from Citys where ID=" & val(label1.text)
on the form2 load
 
whoa.. that confused me... put it lame mens term.. i couldnt tell if that was code i didnt understand... or you were giving a vague idea like i did hehe...


and this ....

then I'm facing my other problem, how to open the form2 and retrive the other fields that belongs to "Id 001"

....
what did you mean.. you have information on a form? and you were trying to get it? whats on the form... like say i clicked over florida... does that form hold like all the information on oranges? and stats? if so couldnt you do like text1 = form2.text2.caption or something? im not sure im catching what ya mean..
 
labels have captions so you would need
"select * from Citys where ID=" & val(label1.caption)
You can set the .dataMemeber properties at design time and then set the .dataSource properties at run-time, depending on which label is clicked on.

Using the format you are, your labels need only store "001" etc as this is all you need to provide in your select statement.

I would write the form_load proceedure in the calling form by doing something like
Load Form2
Label1.dataMember = .....
etc for all bound items
Form2.Show
Me Unload
 
OK,
I think I expressed myself badly.
On a form I put in a Picture box (picture1) and on that picturebox I put in several labelboxes and made those transparent so they can be "hotspots" cause in that picturebox i have a picture of a map. What I'm trying to figure out is how to get a specific post from the database.
If I click on one label it will load form2 wich is the dataform and show that specific post.
Map of US, click on Florida and form2 pops up showing me information on....Florida, which is located in the database.

Oh, and thanks for trying to help me even though I express myself poorly
 
Given your status with the transparent labels on top of the picture box.

In form2, I would set up a public variable.

Public fStr_StateQuery as String

I would then place in the .Tag property of each label, the SQL Statement to retrieve the information for that state.
Then in the click event

Private Sub lblLabel_Click()

Load form2
form2.fStr_StateQuery = lblLabel.Tag
form2.Show

End Sub

Now form2 will have the SQL Statement that you can use to open a recordset and populate the information on the form. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
Form2 still opens with the first record in the database.
Maybe I've done something wrong??
Here's my code:

Form1

Private Sub Label1_Click()
Load form2
form2.fStr_StateQuery = Label1.Tag
form2.Show
End Sub

In the TAG property of label1

SELECT maincitys.CityID, maincitys.CityName, maincitys.Population FROM maincitys WHERE (((maincitys.CityName) Like "Stavanger"));

Form2

Dim WithEvents adoPrimaryRS As Recordset
Dim mbChangedByCode As Boolean
Dim mvBookMark As Variant
Dim mbEditFlag As Boolean
Dim mbAddNewFlag As Boolean
Dim mbDataChanged As Boolean
Public fStr_StateQuery As String

Private Sub Form_Load()
Dim db As Connection
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = City.mdb;"

Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open "select CityID,CityName,Population from maincitys Order by CityID", db, adOpenStatic, adLockOptimistic

Dim oText As TextBox
For Each oText In Me.txtFields
Set oText.DataSource = adoPrimaryRS
Next

mbDataChanged = False
End Sub
 
I think you are opening the Recordset with a hardcoded query, rather than the one from the selected label

adoPrimaryRS.Open "select CityID,CityName,Population from maincitys Order by CityID", db, adOpenStatic, adLockOptimistic

I would change this line to:

adoPrimaryRS.Open fStr_StateQuery, db, adOpenStatic, adLockOptimistic
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
I get an Error message:

Run time error '-2147217908(80040e0c)':
Command text was not set for the commandobject
 
Since the only change was the SQL Statement, then I would like to do two things - 1: Remove the ; from the end of the line, and 2: remove the Like Clause.

We need to change this in the .Tag property, so lets set the .Tag to the following:
SELECT maincitys.CityID, maincitys.CityName, maincitys.Population FROM maincitys WHERE maincitys.CityName = 'Stavanger'
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
I changed the .TAG property but still the same error msg
 
Ok, Lets try making the changes in bold - Note that the Connection Object declaration has been move up for form scope

Dim WithEvents adoPrimaryRS As ADODB.Recordset
Dim db As ADODB.Connection
Dim mbChangedByCode As Boolean
Dim mvBookMark As Variant
Dim mbEditFlag As Boolean
Dim mbAddNewFlag As Boolean
Dim mbDataChanged As Boolean
Public fStr_StateQuery As String

Private Sub Form_Load()
Set db = New ADODB.Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = City.mdb;"

Set adoPrimaryRS = New ADODB.Recordset
adoPrimaryRS.Open fStr_StateQuery, db, adOpenStatic, adLockOptimistic, adCmdText

Dim oText As TextBox
For Each oText In Me.txtFields
Set oText.DataSource = adoPrimaryRS
Next

mbDataChanged = False
End Sub
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
It worked great when I commentet out the load form2 event

Private Sub Label1_Click()

'Load form2

form2.fStr_StateQuery = Form1.Label1.Tag
form2.Show
End Sub

[thumbsup]
Thank you for all your help I really appriciate it.
 
Thank you for the feedback JanTore, but this was a team efffort. Both unborn and perplexed contributed, so I have extended the appreciation to them as well.
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top