Hi all!
I need help with Visual Basic
I am trying to build a program in which the user types a question into a text box. Then the program looks for that question in a database (access database to be specific) and returns the appropriate answer from the database. I already started and did some coding. I already added the Microsoft DAO 3.6 object library as required. The code is as below:

Dim dbMyDB As Database
Dim rsMyRS As DAO.Recordset

Private Sub Form_Load()
    Set dbMyDB = OpenDatabase("QA.mdb")
    Set rsMyRS = dbMyDB.OpenRecordset("QADB", dbOpenDynaset)
End Sub

Private Sub cmdGiveAnswer_Click()
rsMyRS.FindFirst "Qes=" & Str(txtQuestion.text) 
'this is supposed to search the database for the text in the textbox; txtQuestion. Qes is the field name of the column in which the questions are stored, in the database

lblAnswer.Caption = rsMyRS!Answer
 'Answer is the name of the field in which the answers are stored.

End Sub

When I run the app and as a trial, if I type the text "C" into the text box, I get the following error:

Run-time error '3070':

The Microsoft Jet database engine does not recognize 'C' as a valid field name or expression.

Please tell me what I'm doing wrong!!!

This is just the base idea for the program. What I actually mean to do is this. Every time a person asks a question from the program, it looks up that text and give the answer. If it can't find that text in the database, then it asks the user for an appropriate answer and save both the new question and answer in the database. As more people use the program, the database gets bigger, making the program more "smarter"

All help in helping me to try and make a complete version of this program will be appreciated. Thanks to all of you in advance

You have to quote string like this

rsMyRS.FindFirst "Qes= '" & replace(txtQuestion.text, "'", "''") & "'")

btw get rid off VB6 and move to C#, VB6 was hot 10+ years ago - not bad for legacy projects but new app should be written in something more recent.

Thanks for you're advice, but I already solved my problem using a different way:

Dim dbMydb As Database
Dim rsMyRS As DAO.Recordset

Private Sub cmdGo_Click()
    Dim question As String
    Dim answer As String
    Dim newA As String
    Dim newQ As String
lblA.Caption = ""
        answer = ""
        Set dbMydb = OpenDatabase(App.Path + "\Answers.mdb")
        Set rsMyRS = dbMydb.OpenRecordset("Ans", dbOpenDynaset)
        question = txtQ.Text
        rsMyRS.MoveFirst
        Do
            If rsMyRS![Quest] = question Then
                answer = rsMyRS![Answ]
                Exit Do
            Else
                rsMyRS.MoveNext
            End If
        Loop Until rsMyRS.EOF
        lblA.Caption = answer
        If answer = "" Then
            newQ = txtQ.Text
            lblA.Caption = "I'm sorry but I don't know how to answer that please tell me the answer"
            newA = InputBox("Please tell me the answer for that question so that I can answer it the next time you ask it", "New Question")
            If newA <> "" Then
                rsMyRS.AddNew
                rsMyRS!Quest = newQ
                rsMyRS!Answ = newA
                rsMyRS.Update
            End If
        End If

Thanks for replying any way. I attached the finished program so that you can see what it is like.
Thanks for The advice :)

i want to design an application with 10 checkboxes from 0 to 9 and 1 button add. after on clicking add, the sum of 2digits selected should be displayed a label

commented: This thread is 3 years old. If you want help, start a new thread. -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.