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

Use 2 Unbound txt boxes to retrieve records

Status
Not open for further replies.

skamran

Technical User
May 21, 2002
3
US
Basically, I am trying to retrieve records related to information provided in 2 text boxes. So far - the code below fails to work.

I appreciate any help. Thank you.


On Error GoTo Err_Command4_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim stLinkCriteria1 As String

stDocName = "Test"

If stLinkCriteria = "[ID]=" & "'" & Me![Text0] & "'" Then


stLinkCriteria1 = "[Name]=" & "'" & Me! [Text2] & "'"


DoCmd.OpenForm stDocName, , , stLinkCriteria
 
Just a quick stab in the dark. Try this:

Change: If stLinkCriteria = "[ID]=" & "'" & Me![Text0] & "'" Then stLinkCriteria1 = "[Name]=" & "'" & Me! [Text2] & "'"

To: If stLinkCriteria Like "[ID]='" & Me![Text0] & "'" Then
stLinkCriteria1 = "[Name]='" & Me! [Text2] & "'"

When comparing strings use "Like"; the equals sign "=" is for numeric comparisons.

Rod
 
First - thanks for your email.
I tried the modification you suggested; however VB does not like the first part of the code.

If stLinkCriteria Like "[ID]= ""
& Me![Text0]
& "'" Then


stLinkCriteria1 = "[Name]="" & Me! [Text2] & " '
 
You need single quotes and double quotes in your expression. I've added spaces for clarification.

To: If stLinkCriteria Like "[ID]=' " & Me![Text0] & " ' " Then
stLinkCriteria1 = "[Name]=' " & Me! [Text2] & " ' "
 
Skamran

Your post suggests that you have not read my code example carefully enough. I specified single quotes within the statement, just like Sko has pointed out. If you follow the examples carefully it should work.

Rod

Basically we all need a little space.

 
hello i am having some difficulties and if anyone has a solution i am all ears...

anyway, right now i am using unbounded textboxes on one form to gather the search requirements for data on the next for.. the code looks like so:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "letter1_Households"
stLinkCriteria = "[Name]=" & "'" & Me![Text15] & "'"
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria

it works well but i need to figure out a way in which to get all records containing what is entered. for instance say i am searching last names and enter jack... now all i would get is everyone with a last name of jack but i want to be able to get jackson, or some toher entry that contains jack....
i am really stuck on this one so if anyone has ideas i would be most grateful

thanks and everyone have a nice day
travis
 
Try this:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "letter1_Households"
stLinkCriteria = "[Name]=" & "'*" & Me![Text15] & "*'"
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria

Rod
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top