Having trouble with seek or find functions

04-16-2004, 01:46 PM
I have an Access database with two tables. They are linked together with the primary key of one being a relationship field of the second. I have also made a query for this called qTask.

In VB I have a data control (DAO) that have a slew of text boxes and labels linked to it to gather the fields in the record so the user will have more of a user friendly form based app. Now the data control is set up as a dynaset Recordset type because of the need to pull information from both tables with a query statment for a recordsource that sorts out based on a field.


qTask is the query that I made in Access that combines the two tables.cvsp is a field that separated standard from non standard.

Now all the fields are populated and everything works fine. I now need to make a button that allows them to search by task number(primary key of second table) and still populate the fields from both tables. I know that a seek function is the best to use but only useable on a table recordset and i am using a dynaset. I tried to use the findfirst method but it is not working. My code on the Sub click for the search button is as follows:

Private Sub cmdSearch_Click()

Dim strTask As String

strTask = InputBox("Enter the task number that you want to search for")
datCorporate.Recordset.FindFirst "tasknumber = """ & strTask & """"

If datCorporate.Recordset.NoMatch = True Then
MsgBox "No match could be found - - - Try Again"
End If

End Sub

The button is named cmdSearch, the data control is datCorporate, tasknumber is the field name in the access table that I am trying to do the search on. strTask is a variable that I am using to retrieve a string from the user to base the search on.

Any help would be a greatly appreciated.

Thanks in advance

04-16-2004, 02:00 PM
Is tasknumber numeric in your database?
As is: datCorporate.Recordset.FindFirst "tasknumber = """ & strTask & """"
Try: datCorporate.Recordset.FindFirst "tasknumber = " & strTask

04-16-2004, 02:19 PM
Ok that worked on that one thanks!

Now I think I still have the code messed up on this one also but here it is and this one is text the last one was an autonumbered primary key.

Private Sub Command1_Click()

Dim strPerm As String

strPerm = InputBox("Enter the Tension Perm Machine Number that you want to search for")
datCorporate.Recordset.FindFirst "tensionperm =""" & strPerm & """"

If datCorporate.Recordset.NoMatch = True Then
MsgBox "No match could be found - - - Try Again"
End If

End Sub

Basically the same but the strPerm is actually a text property and the code has to have the "strPerm" from my understanding for it to recognize it as a string? so thats y there are """&strPerm&"""

This time the record field that I am perferming the find on is tensionperm and is primary key of one of the tables whereas the task number was the primary key of the other table.

Thanks for fixing the other problem. Maybe I should just change it to a numeric property ;)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum