| | |
Question answer database program in Visual Basic 6
![]() |
•
•
Join Date: Aug 2009
Posts: 2
Reputation:
Solved Threads: 0
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:
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
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:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
Last edited by UV1995; Aug 13th, 2009 at 8:51 pm.
You have to quote string like this
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.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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.
•
•
Join Date: Aug 2009
Posts: 2
Reputation:
Solved Threads: 0
Thanks for you're advice, but I already solved my problem using a different way:
Thanks for replying any way. I attached the finished program so that you can see what it is like.
Thanks for The advice
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
![]() |
Similar Threads
- Visual Basic Timer/Clock/Countdown. (Visual Basic 4 / 5 / 6)
- Conversion to Visual Basic (Visual Basic 4 / 5 / 6)
- VB6 Database Program (Visual Basic 4 / 5 / 6)
- display checkbox value from MS access in visual basic 6 form (Visual Basic 4 / 5 / 6)
- visual basic and access (Visual Basic 4 / 5 / 6)
- Problem in Serial Communication In Visual Basic (Visual Basic 4 / 5 / 6)
- variable argument list in Visual Basic (Visual Basic 4 / 5 / 6)
- Visual Basic and .asx files (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: ADO DataGrid order columns
- Next Thread: Issue with saving and reading data from .txt file
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





