Solved

Findfirst using a textbox value

Posted on 2000-02-20
10
550 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 150 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 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…

759 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