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

combobox selecting wrong record 4

Status
Not open for further replies.

DSGF

Technical User
Mar 22, 2008
17
US
I have created a form with two comboboxes. One selects company representatives by zip and the other by city. Zip combo works fine because there is always only one zip. There can be several like city names so in my combobox I show city, county and state.
However, whenever a city is selected, it chooses the 1st record in the database no matter which was selected in the combobox.
I see that this is happening because the code says rs.FindFirst...

Code:
Private Sub Combo60_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[PO_NAME] = '" & Me![Combo60] & "'"
    Me.Bookmark = rs.Bookmark
            
    Combo60.Value = PO_NAME.Value
    Combo40.Value = ZIP_CODE.Value
    etc.....

I tried the following code but it does not...

Code:
Set rs = Me.Recordset.Clone
    rs.FindFirst "[PO_NAME] = '" & Me![Combo60] & "AND [ST_ABBREV] = " & Me.Combo60.Column(3) & "'"
    Me.Bookmark = rs.Bookmark

Is there a simple solution to my questions or am I in over my head? Thanks for any help.
 
ok, I tried this...
Code:
Set rs = Me.Recordset.Clone
    rs.FindFirst "[PO_NAME] = '" & Me![Combo60] & "WHERE [ST_ABBREV] = " & Me.Combo60.Column(3) & "'"
    Me.Bookmark = rs.Bookmark
but this did not work either. It simply returns the 1st record in the table as if I did not enter any critia at all.

I did not get any suggetions to my original question.
Is my question very unclear and needs to be re-written or is the answer just too obvious and I need to be in a more basic thread?
Any help is appriciated.
 
I think your statement should read

if both combo60 col0(zip) and col 2(state) are strings
Set rs = Me.Recordset.Clone
rs.FindFirst "[PO_NAME] = '" & Me![Combo60] & "' WHERE [ST_ABBREV] = '" & Me.Combo60.Column(3) & "'"
Me.Bookmark = rs.Bookmark


if combo60 col0(zip)is a number and col 2(state) is a strings use
Set rs = Me.Recordset.Clone
rs.FindFirst "[PO_NAME] = " & Me![Combo60] & "WHERE [ST_ABBREV] = '" & Me.Combo60.Column(3) & "'"
Me.Bookmark = rs.Bookmark

ck1999
 
Actually I think you should go back to the and statement

if both combo60 col0(zip) and col 2(state) are strings
Set rs = Me.Recordset.Clone
rs.FindFirst ("[PO_NAME] = '" & Me![Combo60] & "' AND [ST_ABBREV] = '" & Me.Combo60.Column(3) & "'")
Me.Bookmark = rs.Bookmark


if combo60 col0(zip)is a number and col 2(state) is a strings use
Set rs = Me.Recordset.Clone
rs.FindFirst ("[PO_NAME] = " & Me![Combo60] & " And [ST_ABBREV] = '" & Me.Combo60.Column(3) & "'")
Me.Bookmark = rs.Bookmark

ck1999
 
Yes, That's AND is exactly what I needed.
Thank you very much ck1999!
 




DSGF,


I notice that you have been a member for just couple of weeks, and ck1999 seems to have provided a pretty good tip. When you get a tip that is a valuable post, it is customary to
[blue]
Thank Tek-Tip Contributor
for this valuable post!
[/blue].

The Stars accomplish several important things.

First, it gives positive feedback to contributors, that their posts have been helpful.

Second, it identifies threads as containing helpful posts, so that other members can benefit.

And third, it identifies the original poster (that's YOU, BTW), as a grateful member, that not only receives, but is willing to give tokens of thanks.

Skip,

[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue]
 
Skip,
Thanks very much for your helpful advice. I am new to Forums and did not even notice the Thank link. Thank you for pointing me to it. I did go ahead and thank ck1999 and will thank others as I go.
Another question. When a question is answered, should I somehow close the thread? How? Thanks for any further advice.
 
DSGF . . .

For insight into Tek-Tips etiquette, hava look at either of the links at the bottom of any of my posts . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top