EdwardMartinIII
Technical User
If this has been answered elsewhere, please point me in the right direction -- I've searched the FAQ and the forum and I THOUGHT I'd pretty much exhausted the examples in Access.
I have a form.
On the form is a list box "StoryListBox"
StoryListBox contains a list of Story Titles culled from the one table in the file
On the form is a text box "Text_Story"
What I would LIKE is when I click on one of the stories listed in "StoryListBox", a query is built to extract the body of the story from the table and display it in "Text_Story".
This is what I have so far:
I have a form.
On the form is a list box "StoryListBox"
StoryListBox contains a list of Story Titles culled from the one table in the file
On the form is a text box "Text_Story"
What I would LIKE is when I click on one of the stories listed in "StoryListBox", a query is built to extract the body of the story from the table and display it in "Text_Story".
This is what I have so far:
Code:
Private Sub StoryListBox_Click()
Dim Location, SQLString, qdf, dbs
Location = StoryListBox.ListIndex
Label13.Caption = StoryListBox.ItemData(Location) ' Print the Title
' Build the Query String
SQLString = "SELECT [Table1].[Body (HTML)] FROM Table1 WHERE [Table1].[Title]=" & Chr(34) & StoryListBox.ItemData(Location) & Chr(34) & ";"
' Create the dbQuery
Set qdf = CurrentDb.CreateQueryDef("StoryRetrieve", SQLString)
Label16.Caption = SQLString ' So I can see my SQL string
' Populate Text_Story.text via StoryRetrieve
' Delete the Query
DoCmd.DeleteObject acQuery, "StoryRetrieve"
End Sub
[\code]
Label16 is how I peek at the SQLString as I construct it. The SQLString seems to do just fine and the Query gets built hunky dory. When I manually run the Query, it works great each time, so I believe my query is formulated correctly.
When I try
[code]Me!Text_Story.Text = StoryRetrieve[\code]
I receive an error that reads [i]Run-time error '2185': You can't reference a property or method for a control unless the control has the focus.[/i]
Now, I already have a line (which I've deleted from my sample listing) that changes the background color of "Text_Story" and it seems to be able to do so just fine, so I'm not entirely sure why it suddenly loses focus (this isn't one of those ADD controls, is it?)
Then I tried
[code]Me!Text_Story.DefaultValue = StoryRetrieve[\code]
It [i]doesn't[/i] crash, but populates the window with
[i]#Name?[/i]
as does
[code]Me!Text_Story.DefaultValue = (StoryRetrieve)[\code]
This seems embarrasingly fundamental and I'll admit this is my first attempt at making a database and a little form, so I might be missing something profoundly simple. With that in mind, I sure would appreciate someone pointing me in the right direction!
Thanks!
Edward