943,699 Members | Top Members by Rank

Ad:
Aug 13th, 2009
0

Question answer database program in Visual Basic 6

Expand Post »
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:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim dbMyDB As Database
  2. Dim rsMyRS As DAO.Recordset
  3.  
  4. Private Sub Form_Load()
  5. Set dbMyDB = OpenDatabase("QA.mdb")
  6. Set rsMyRS = dbMyDB.OpenRecordset("QADB", dbOpenDynaset)
  7. End Sub
  8.  
  9. Private Sub cmdGiveAnswer_Click()
  10. rsMyRS.FindFirst "Qes=" & Str(txtQuestion.text)
  11. '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
  12.  
  13. lblAnswer.Caption = rsMyRS!Answer
  14. 'Answer is the name of the field in which the answers are stored.
  15.  
  16. 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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
UV1995 is offline Offline
10 posts
since Aug 2009
Aug 14th, 2009
1

Re: Question answer database program in Visual Basic 6

You have to quote string like this
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 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.
Reputation Points: 10
Solved Threads: 9
Junior Poster
VIeditorlover is offline Offline
137 posts
since Dec 2007
Aug 15th, 2009
0

Re: Question answer database program in Visual Basic 6

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

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim dbMydb As Database
  2. Dim rsMyRS As DAO.Recordset
  3.  
  4. Private Sub cmdGo_Click()
  5. Dim question As String
  6. Dim answer As String
  7. Dim newA As String
  8. Dim newQ As String
  9. lblA.Caption = ""
  10. answer = ""
  11. Set dbMydb = OpenDatabase(App.Path + "\Answers.mdb")
  12. Set rsMyRS = dbMydb.OpenRecordset("Ans", dbOpenDynaset)
  13. question = txtQ.Text
  14. rsMyRS.MoveFirst
  15. Do
  16. If rsMyRS![Quest] = question Then
  17. answer = rsMyRS![Answ]
  18. Exit Do
  19. Else
  20. rsMyRS.MoveNext
  21. End If
  22. Loop Until rsMyRS.EOF
  23. lblA.Caption = answer
  24. If answer = "" Then
  25. newQ = txtQ.Text
  26. lblA.Caption = "I'm sorry but I don't know how to answer that please tell me the answer"
  27. newA = InputBox("Please tell me the answer for that question so that I can answer it the next time you ask it", "New Question")
  28. If newA <> "" Then
  29. rsMyRS.AddNew
  30. rsMyRS!Quest = newQ
  31. rsMyRS!Answ = newA
  32. rsMyRS.Update
  33. End If
  34. 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
Attached Files
File Type: zip Virtual Friend.zip (23.5 KB, 56 views)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
UV1995 is offline Offline
10 posts
since Aug 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: ADO DataGrid order columns
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Issue with saving and reading data from .txt file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC