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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to save last five entries in an unbound combo box

Status
Not open for further replies.

zionman4

Programmer
Mar 12, 2003
48
US
Hello everyone,
I have created a similar search form as the one used when pressing ctrl f. I know want to add the same functionality to an unbound combo box, of saving the last 5 search items. I tried adding it through code using value list as the source but I'm unable to do it. Any suggestions in how to do this?
Here is the code I had originally created. Thanks in advance!

Private Sub cboSearch1_AfterUpdate()
Dim vVal1 As Variant
Dim vVal2 As Variant
Dim vVal3 As Variant
Dim vVal4 As Variant
Dim vVal5 As Variant

vVal5 = Nz(vVal4, "")
vVal4 = Nz(vVal3, "")
vVal3 = Nz(vVal2, "")
vVal2 = Nz(vVal1, "")
vVal1 = Me.cboSearch1

'Check Values
If Len(vVal1) > 0 And Len(vVal2) = 0 Then
Me.Count = 1
Me.RecordSource = vVal1
ElseIf Len(vVal1) > 0 And Len(vVal2) > 0 And Len(vVal3) = 0 Then
Me.Count = 2
Me.RecordSource = vVal1 & ";" & vVal2
ElseIf Len(vVal1) > 0 And Len(vVal2) > 0 And Len(vVal3) > 0 And Len(vVal4) = 0 Then
Me.RecordSource = vVal1 & ";" & vVal2 & ";" & vVal3
ElseIf Len(vVal1) > 0 And Len(vVal2) > 0 And Len(vVal3) > 0 And Len(vVal4) > 0 And Len(vVal5) = 0 Then
Me.RecordSource = vVal1 & ";" & vVal2 & ";" & vVal3 & ";" & vVal4
Else
Me.RecordSource = vVal1 & ";" & vVal2 & ";" & vVal3 & ";" & vVal4 & ";" & vVal5
End If

End Sub
 
This looks like Access type code... So Me would be the form the combo box is on. Changing that record source is the record source of the form... Try something more like...


Code:
Me!cboSearch1.RecordSource = vVal1

I can't remember tinkering with a value list like this myself... It seems that you may also need the refresh or requery method to have the list show your items as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top