G
Guest
This is something I posted on a few weeks ago, and has come round again, but
I'm still stumped. (I don't have a coding background unfortunately, but am
very familiar with Access, and have kind of picked up bits along the way - so
I can kind of see and understand how code works, and what it's doing, even if
I can't write it from scratch sort of thing.)
Basically I'm involved in a project to create a database of stock
photography, the purpose of which will be that people can search for photos
based on keywords attached to each in a broswer environment.
I've taken care of that side of things, with a little intranet site up and
running, and working well.
But the data entry side of things isn't quite there. We want users to be
able to select keywords from a pre-defined selection so as to keep
consistancy, and eliminate typos.
At the moment I have a table tbl_Photos with various fields including
'Keywords'.
In the data entry form that holds all the photo details, there is a drop
down box with various categories - eg 'Flora and Fauna', 'Notable Buildings'
etc. which is a bound field 'Categories'.
The idea here is to have manageable lists of keywords rather than one long
list.
How it works is that the After Update has the expression :
Private Sub Categories_AfterUpdate()
Me.Keywords.RowSource = "SELECT Keyword FROM" & _
" tbl_KeywordsTEMP WHERE CategoryID = " & Me.Categories & _
" ORDER BY Keyword"
Me.Keywords = Me.Keywords.ItemData(0)
End Sub
Which selects the Keywords from a tbl_keywordsTEMP and populates a unbound
list box with the relevant keywords for the selected category.
From here, it's possible to select keywords from the current list displayed,
and populate a field 'KeywordsNew' in the tbl_Photos, using the following
expression in the After Update of the unbound list box :
Private Sub Keywords_AfterUpdate()
Dim ctlSource As Control
Dim ctlDest As Control
Dim strItems As String
Dim intCurrentRow As Integer
Set ctlSource = Me![Keywords]
Set ctlDest = Me![KeywordsNew]
' Loop through selected items; add to string
For intCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(intCurrentRow) Then
strItems = strItems & ctlSource.Column(0, _
intCurrentRow) & ";"
End If
Next intCurrentRow
' Set destination control to string
ctlDest = strItems
' Clear memory
Set ctlSource = Nothing
Set ctlDest = Nothing
End Sub
So far so good - it all works a treat.
With one caveat - namely, if you want to enterkeywords from more than one
category, it overwrites the KeywordsNew field, rather than append to any
existing keywords already stored there.
Basically, in order for this all to be working exactly as I'd like, I need
the KeywordsNew field to be able to store a list of keywords selected from
multiple categories, rather than only one or other as it is at the moment.
I've tried to explain that as weel as I can - hope someone a. understands
what I'm trying to achieve, and b. can shed any light on a solution.
Many thanks,
Iain
I'm still stumped. (I don't have a coding background unfortunately, but am
very familiar with Access, and have kind of picked up bits along the way - so
I can kind of see and understand how code works, and what it's doing, even if
I can't write it from scratch sort of thing.)
Basically I'm involved in a project to create a database of stock
photography, the purpose of which will be that people can search for photos
based on keywords attached to each in a broswer environment.
I've taken care of that side of things, with a little intranet site up and
running, and working well.
But the data entry side of things isn't quite there. We want users to be
able to select keywords from a pre-defined selection so as to keep
consistancy, and eliminate typos.
At the moment I have a table tbl_Photos with various fields including
'Keywords'.
In the data entry form that holds all the photo details, there is a drop
down box with various categories - eg 'Flora and Fauna', 'Notable Buildings'
etc. which is a bound field 'Categories'.
The idea here is to have manageable lists of keywords rather than one long
list.
How it works is that the After Update has the expression :
Private Sub Categories_AfterUpdate()
Me.Keywords.RowSource = "SELECT Keyword FROM" & _
" tbl_KeywordsTEMP WHERE CategoryID = " & Me.Categories & _
" ORDER BY Keyword"
Me.Keywords = Me.Keywords.ItemData(0)
End Sub
Which selects the Keywords from a tbl_keywordsTEMP and populates a unbound
list box with the relevant keywords for the selected category.
From here, it's possible to select keywords from the current list displayed,
and populate a field 'KeywordsNew' in the tbl_Photos, using the following
expression in the After Update of the unbound list box :
Private Sub Keywords_AfterUpdate()
Dim ctlSource As Control
Dim ctlDest As Control
Dim strItems As String
Dim intCurrentRow As Integer
Set ctlSource = Me![Keywords]
Set ctlDest = Me![KeywordsNew]
' Loop through selected items; add to string
For intCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(intCurrentRow) Then
strItems = strItems & ctlSource.Column(0, _
intCurrentRow) & ";"
End If
Next intCurrentRow
' Set destination control to string
ctlDest = strItems
' Clear memory
Set ctlSource = Nothing
Set ctlDest = Nothing
End Sub
So far so good - it all works a treat.
With one caveat - namely, if you want to enterkeywords from more than one
category, it overwrites the KeywordsNew field, rather than append to any
existing keywords already stored there.
Basically, in order for this all to be working exactly as I'd like, I need
the KeywordsNew field to be able to store a list of keywords selected from
multiple categories, rather than only one or other as it is at the moment.
I've tried to explain that as weel as I can - hope someone a. understands
what I'm trying to achieve, and b. can shed any light on a solution.
Many thanks,
Iain