Populate a field with info not in the database? (1 Viewer)

82412

Registered User.
Local time
Today, 04:23
Joined
Dec 15, 2006
Messages
25
I have a list box on a form. It shows Code01 on the first line, Code02 on the second, Code03 on the third and so on, and is set to populate a text box on the same form.

What I want to happen is that when Code01 is clicked a specific short phrase or sentence appears in the text box, a different specific phrase or sentence for Code02 etc.

These phrases/sentences are not in the database. How can I store them and then call them according to which Code Number is clicked?
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 20:23
Joined
Aug 30, 2003
Messages
36,134
They would need to be stored. I would have a field for the code and a field for the phrase. Then it's a simple matter to get the phrase associated with a code.
 

KeithG

AWF VIP
Local time
Yesterday, 20:23
Joined
Mar 23, 2006
Messages
2,592
Paul is correct. Make a table with two fields Code (PK) and message. The you can just lookup the message for the corresponding code.
 

missinglinq

AWF VIP
Local time
Yesterday, 23:23
Joined
Jun 20, 2003
Messages
6,420
And you or your users can easily Add/Edit your codes and associated text without having to go into your database's code module.

Linq
 

82412

Registered User.
Local time
Today, 04:23
Joined
Dec 15, 2006
Messages
25
At the moment I have achieved what I wanted by simply putting the short phrases into the list box - they are very short so they don't take up too much space on the form.

And now the inevitable follow-up question! Using this simple list box to text box method, is it possible to populate the text box with the current date as well as the phrase when the phrase is clicked in the list box? I tried inserting =Date() in the row source but that simply resulted in =Date() being repeated in the text box along with the phrase.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 20:23
Joined
Aug 30, 2003
Messages
36,134
Post the code you're trying to use. The Date() function would be the way to go.
 

82412

Registered User.
Local time
Today, 04:23
Joined
Dec 15, 2006
Messages
25
I merely used the Control Wizard. The resultant code, as you can see, is unremarkable -



Private Sub List122_AfterUpdate()

End Sub

Private Sub List122_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub List122_Click()

End Sub

Private Sub List122_DblClick(Cancel As Integer)

End Sub

Private Sub List122_Enter()

End Sub

Private Sub List122_Exit(Cancel As Integer)

End Sub

Private Sub List122_GotFocus()

End Sub

Private Sub List122_KeyDown(KeyCode As Integer, Shift As Integer)

End Sub

Private Sub List122_KeyPress(KeyAscii As Integer)

End Sub

Private Sub List122_KeyUp(KeyCode As Integer, Shift As Integer)

End Sub

Private Sub List122_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

End Sub

Private Sub List122_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

End Sub

Private Sub List122_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

End Sub



I entered =Date() into the Row source (illustrated)



but this is the result that appears in the list box, and in the text box when I click on the entry in the list box
 

82412

Registered User.
Local time
Today, 04:23
Joined
Dec 15, 2006
Messages
25
I've got round the problem by creating a text box bound to a new date field with =Date() as its default value and placing code in the After Update event of the List box so that the current date is entered in the new text box when one of the phrases in the list box is clicked.

It would still be interesting to know if this could have been achieved via the list box alone, though.
 

Users who are viewing this thread

Top Bottom