Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Findfirst using a textbox value

Posted on 2000-02-20
10
Medium Priority
?
582 Views
Last Modified: 2013-12-25
What I am trying to do is use the findfirst function passing a value from a text box as the value to be found
The following code works with out errors and will find the value –85 in a check ledger database using a bound database control. I have a textbox where they type in the value of the check they are searching for and in the following code I want it to use this value instead of –85. What I can not get it to do is accept the syntax that would normally be used to pass this variable. The “” are needed because this statement is being passed as an SQL statement and if I replace –85 with the name of a variable or textbox field such as amountvar.text it reads it as I am literally looking for amountvar.text in the database table in the amount field.

Private Sub findnow_Click()
Data1.Recordset.findfirst "amount='-85'"
If Data1.Recordset.NoMatch Then
    MsgBox "No Such Record Found"
End If

End Sub

Keep in mind I am a very novice programmer so please be very clear and detailed.
0
Comment
Question by:srose6
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 25

Expert Comment

by:clockwatcher
ID: 2541449
Data1.Recordset.findfirst "amount='" & amountvar.text & "'"
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 2541602
clockwatcher is correct, though if this is a numeric field, the additional single quote characters are not necessary.

Data1.Recordset.FindFirst "amount = " & amountvar.Text

0
 
LVL 18

Accepted Solution

by:
deighton earned 600 total points
ID: 2541874
Data1.Recordset.FindFirst "amount=" & Chr(39) & CStr(amountvar.Text) & Chr(39)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:srose6
ID: 2543230
Adjusted points to 150
0
 
LVL 4

Author Comment

by:srose6
ID: 2543231
deighton you are the man. I have increased the points and requested more information. Either way you will get the 100 points with a grade of "A"

One more detail I could use. I have several fields for query information. One for amount, check number, and one for date. They are all fields in the same dataset. How do I get it to check say the check number and the amount. The text box for check number is chnum.text and the text box for check amount is amountval.text. Is there an anding feature that will only return a response if the values for both fields match in a record. I have tried using AND between two statements formated as the one you gave but I get the error "type mismatch".
Private Sub findnow_Click()
Data1.Recordset.FindFirst "amount=" & Chr(39) & CStr(amountval.Text) & Chr(39) And "Check=" & Chr(39) & CStr(chnum.Text) & Chr(39)
If Data1.Recordset.NoMatch Then
    MsgBox "No Such Record Found"
End If
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2543276
This line must be like this:
Data1.Recordset.FindFirst "amount=" & Chr(39) & CStr(amountval.Text) & Chr(39) & " And Check=" & Chr(39) & CStr(chnum.Text) & Chr(39)
0
 
LVL 4

Author Comment

by:srose6
ID: 2543603
You guys have been great. Works like a charm. I have two books on VB. It sounds like I need to by one on VB Programming to get information this specific.

Thanks again
Steve
MCSE+I
0
 
LVL 18

Expert Comment

by:deighton
ID: 2545311
The basic theory behind it is to create a string in a variable which looks like the one you would write in a program to do the select you want.  

The & operator is probably explained in a text under 'string operations'

0
 
LVL 4

Author Comment

by:srose6
ID: 2546274
What does Chr(39) stand for.

What I meant to say is I need to buy a book on VB Database programing. Do you have any books you would recomend on VB Database programing or VB in general.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 2546318
chr(39) is the single quote character ', chr(34) is the double quote character "
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question