Question answer database program in Visual Basic 6

Reply

Join Date: Aug 2009
Posts: 2
Reputation: UV1995 is an unknown quantity at this point 
Solved Threads: 0
UV1995 UV1995 is offline Offline
Newbie Poster

Question answer database program in Visual Basic 6

 
0
  #1
Aug 13th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 97
Reputation: VIeditorlover is an unknown quantity at this point 
Solved Threads: 5
VIeditorlover's Avatar
VIeditorlover VIeditorlover is offline Offline
Junior Poster in Training

Re: Question answer database program in Visual Basic 6

 
0
  #2
Aug 14th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 2
Reputation: UV1995 is an unknown quantity at this point 
Solved Threads: 0
UV1995 UV1995 is offline Offline
Newbie Poster

Re: Question answer database program in Visual Basic 6

 
0
  #3
Aug 15th, 2009
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, 2 views)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC