Solved

Findfirst using a textbox value

Posted on 2000-02-20
10
528 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 150 total points
ID: 2541874
Data1.Recordset.FindFirst "amount=" & Chr(39) & CStr(amountvar.Text) & Chr(39)
0
 
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 69

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now