PDA

View Full Version : FindRecord from combBox



mud2
06-19-2009, 01:34 PM
I'm trying(!) to execute DoCmd.FindRecord Something....
where Something is in Table1
If I input Something through an input box, the command works, but if I display the contents of table1 in a combobox and choose the value of Something from the box, the findrecord does not work?
So I ask for help after 48 hours of trying all permutations abd combinations of the DoCmd.FindRecord argumnets!

hansup
06-19-2009, 04:09 PM
I'm trying(!) to execute DoCmd.FindRecord Something....
where Something is in Table1
If I input Something through an input box, the command works, but if I display the contents of table1 in a combobox and choose the value of Something from the box, the findrecord does not work?
So I ask for help after 48 hours of trying all permutations abd combinations of the DoCmd.FindRecord argumnets!Not sure I understand what you're trying to do. Sounds like you want to choose a value from your combobox and have the form's current record display the record which matches that value. If that is your goal, take a look at the sample database in the attached zip file.

The combo's AfterUpdate event is what drives it:
Private Sub cboChooser_AfterUpdate()
Dim rs As DAO.Recordset
Set rs = Me.Recordset
rs.FindFirst "tid = " & Me.cboChooser.Column(0)
Set rs = Nothing
End Sub

mud2
06-19-2009, 07:08 PM
To Hansup:
Thanks! Your example works, but not for me!
But seeing the Quotes marks in your example alerted me..to Access's involved, uncomprehensible "Literals"
The field in my table is ID, and my combo is combo31, so
If you change
rs.findfirst "tid = " & MeCombo31.column(0)
to
rs.findfirst "ID = " & Chr(39) & combo31.column(0) & Chr(39)
Now it works!

rs.findfirst "Me.combo31.column(0) would probably work also!
mud2...Thanks again!

mud2
06-19-2009, 07:10 PM
The above(?) works for either the afterupdate OR the click !

OBP
06-20-2009, 04:26 AM
The Toolbox Combo Wizard would have done this for you, during the Combo building process you have the Option to "Find a record based on my combo selction" or words to that affect.

mud2
06-20-2009, 10:15 PM
With a slap on the forhead, thanks again...BUT
As usual, ACCESS has a "GOTCHA";
The rs.findfirst method is not Case Sensitive!
Looks like I'll have to open the table and search bitwise!
Another 48 wasted hours. Yes, even in my sleep!

hansup
06-21-2009, 06:33 AM
The rs.findfirst method is not Case Sensitive!
Looks like I'll have to open the table and search bitwise!Look at the StrComp function.

Using the example database from before, I added a record to Table1 with "TWO" in the "something" field, and changed the AfterUpdate code to this:
Private Sub cboChooser_AfterUpdate()
Dim rs As DAO.Recordset
Set rs = Me.Recordset
'rs.FindFirst "tid = " & Me.cboChooser.Column(0)
rs.FindFirst "StrComp(something, '" & Me.cboChooser.Column(1) & "',0) = 0"
Set rs = Nothing
End Sub

OBP
06-21-2009, 10:45 AM
hansup, does that do what mud wants? We tend to forget that you can modify the Search's Filter part and tend to think in terms of straight text or fields.

hansup
06-21-2009, 11:38 AM
hansup, does that do what mud wants? I really don't know, OBP. Originally I showed him a combo with a numeric primary key in the first (hidden) column and text values in the second column. The user's selection from the second column would locate the appropriate record based on its primary key.

However, he is doing something different because case sensitivity is an issue. I hoped StrComp would provide the sensitivity he needs. :-)


We tend to forget that you can modify the Search's Filter part and tend to think in terms of straight text or fields.Sorry, you lost me there. I'll need to think on that one some more.

Regards,
Hans

mud2
06-21-2009, 01:26 PM
It doesnt! I eeven copied (From the above), and set up a DB to fit...still doesn't work!
I thought of trying VAL(Something)..but I can't even get Val() to work!

So I'll go back to a more basic, but simpler approach. Open the database, use .movenext, then strcomp(x,y,0). This has worked for me in the past!
Keep tuned, but don't hold your breath(s)!

OBP
06-22-2009, 03:51 AM
Mud, how about combining the 2, use the find to find the record and then use the strcomp to check it, you can then use findnext if it doesn't match?

OBP
06-22-2009, 03:55 AM
Hans, by this "We tend to forget that you can modify the Search's Filter part and tend to think in terms of straight text or fields." I just meant that we tend to think that you can only use Text or a Field or possibly a variable for the criteria in the Find statement, whereas we may be able to use other functions mixed with them, I have certainly seen Format() used in the Find.

hansup
06-22-2009, 05:29 AM
Hans, by this "We tend to forget that you can modify the Search's Filter part and tend to think in terms of straight text or fields." I just meant that we tend to think that you can only use Text or a Field or possibly a variable for the criteria in the Find statement, whereas we may be able to use other functions mixed with them, I have certainly seen Format() used in the Find.
OK, like how I showed him StrComp in the FindFirst expression! I thought you were saying "consider an approach you haven't tried".

Regards,
Hans

OBP
06-22-2009, 10:52 AM
Your method should have worked, I am not sure why it didn't. :dunno

hatched850
11-18-2009, 09:35 AM
I am trying to do kinda of the samething. I would like to use a selection in one combo box to limit the selection in another combo box.

example:
If you have 3 levels and then want a sub choice for each level

Level 1
Topic 1
Topic 2

hatched850
11-18-2009, 09:36 AM
I am trying to do kinda of the samething. I would like to use a selection in one combo box to limit the selection in another combo box.

example:
If you have 3 levels and then want a sub choice for each level

Level 1
Topic 1
Topic 2
Topic 2
Level 2
Topic 1
Topic 2