Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Findfirst using a textbox value

Posted on 2000-02-20
10
Medium Priority
?
597 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

916 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