Results 1 to 14 of 14

Thread: DOA Problem! Plz Help Me Out!

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    7

    DOA Problem! Plz Help Me Out!

    hi
    i have never worked with the DOA concept before and i am trying to make this work, but im stuck in this problem for so long. plz help me out...
    what i am trying to do here is this:-
    i have made a database using access and included a table in it,both named studentdatabase. there are 2 text boxes corresponding to 2 labels...Name and grade.
    then i have put 1 data control named,data1 of student.
    then i have used 8 command buttons: 1)add new record
    2)edit record
    3)delete record
    4)update database
    then to move between the records(in a data control):- i've used 4 command buttons:-
    5)First
    6)Previous
    7)Next
    8)Last
    The coding is as follows...and i am sure that there is something wrong in the coding. Also the problem that im facing is that when i try to run this ,it doesn't show the labels Name and Grade but rather what i put in the textbox,that is shown in the label also. PLZ HELP ME OUT .....


    VB Code:
    1. Dim db As Database
    2. Dim rs As Recordset
    3.  
    4. Private Sub Command1_Click()
    5. rs.AddNew
    6. Text1.Text = ""                        //add new record command button
    7. Text2.Text = ""
    8. rs.Update
    9. End Sub
    10.  
    11. Private Sub Command2_Click()
    12. If rs.EOF Then
    13. rs.AddNew
    14. Else
    15. rs.Edit
    16. End If
    17. rs!Name = Text1.Text                              //edit record command button
    18. rs!grade = Text2.Text
    19. rs.Update
    20. End Sub
    21.  
    22. Private Sub Command3_Click()
    23. Text1.Text = ""
    24. Text2.Text = ""                                   //delete record  command button
    25. rs.Delete
    26. End Sub
    27.  
    28. Private Sub Command4_Click()
    29. rs.Edit
    30. rs!Name = Text1.Text
    31. rs!grade = Text2.Text                            //update database
    32. rs.Update
    33. End Sub
    34.  
    35.  
    36.  
    37. Private Sub Command5_Click()
    38. Data1.Recordset.MovePrevious
    39. If Data1.Recordset.BOF Then                 //  move previous command button
    40. Data1.Recordset.MoveLast
    41. End If
    42. End Sub
    43.  
    44. Private Sub Command6_Click()
    45. Data1.Recordset.MoveFirst                   //move first command button
    46. End Sub
    47.  
    48. Private Sub Command7_Click()
    49. Data1.Recordset.MoveNext
    50. If Data1.Recordset.EOF Then              //move next command button
    51. Data1.Recordset.MoveFirst
    52. End If
    53. End Sub
    54.  
    55. Private Sub Command8_Click()
    56. Data1.Recordset.MoveLast             //move last command button
    57. End Sub
    58.  
    59. Private Sub form_Load()
    60. Set db = OpenDatabase("C:\Documents and Settings\Administrator\My Documents\studentdatabase.mdb")
    61. Set rs = db.OpenRecordset("studentdatabase", dbOpenDynaset)
    62. If Not rs.EOF Then rs.MoveFirst
    63. End Sub
    64.  
    65. Private Sub Label1_Click()
    66. Char Name = rs!Name
    67. rs.MoveNext                                                      
    68. End Sub
    69.  
    70. Private Sub Label2_Click()
    71. Char grade = rs!grade
    72. rs.MoveNext
    73. End Sub


    Last edited by si_the_geek; Nov 5th, 2005 at 04:40 PM. Reason: added VBCode tags

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: DOA Problem! Plz Help Me Out!

    Hi galmca, welcome to VBForums!

    Your code generally looks ok, but I don't understand why you have a data control (your code provides all the functionality). Issues you are getting could well be due to the data control doing it's thing at the same time as your code is.

    In my opinion, you should remove the data control, and replace all instances of "Data1.Recordset" in your code with "rs". You will need to add the following lines of code to all of the 'Move' subs which are associated with it.
    VB Code:
    1. rs!Name = Text1.Text                            
    2. rs!grade = Text2.Text


    Also, I'm a bit confused, what are these two lines about?
    VB Code:
    1. Char Name = rs!Name
    2. Char grade = rs!grade
    If you want to put the values from the recordset into the labels, you should be using code like this:
    VB Code:
    1. Label1.Caption = rs!Name
    2. Label2.Caption = rs!grade

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    7

    Re: DOA Problem! Plz Help Me Out!

    first of all i wanna say...Thx for ur reply! but now when i do this as u have told me...
    even still it is not working.it is giving me a compile time error called "Method or data member not found", everytime i try to click on any of the "last","next","previous","first" command buttons.... i also don't know why it is still not showing labels as Name and Grade corresponding to two textboxes ,...it always shows some strange values that i give inside the 2 textboxes as name and grade also. i think its becoz of some error in my code in the last two lines of my code ....plz try to check it out now! and let me know where it is still causing problems...i am stuck in this problem!!! Here is the modified code now....:--
    VB Code:
    1. Dim db As Database
    2. Dim rs As Recordset
    3.  
    4. Private Sub Command1_Click()
    5. rs.AddNew
    6. Text1.Text = ""
    7. Text2.Text = ""
    8. rs.Update
    9. End Sub
    10.  
    11. Private Sub Command2_Click()
    12. If rs.EOF Then
    13. rs.AddNew
    14. Else
    15. rs.Edit
    16. End If
    17. rs!Name = Text1.Text
    18. rs!grade = Text2.Text
    19. rs.Update
    20. End Sub
    21.  
    22. Private Sub Command3_Click()
    23. Text1.Text = ""
    24. Text2.Text = ""
    25. rs.Delete
    26. End Sub
    27.  
    28. Private Sub Command4_Click()
    29. rs.Edit
    30. rs!Name = Text1.Text
    31. rs!grade = Text2.Text
    32. rs.Update
    33. End Sub
    34.  
    35.  
    36. Private Sub Command5_Click()
    37. Data1.rs.MovePrevious
    38. If Data1.rs.BOF Then
    39. Data1.rs.MoveLast
    40. rs!Name = Text1.Text
    41. rs!grade = Text2.Text
    42. End If
    43. End Sub
    44.  
    45. Private Sub Command6_Click()
    46. Data1.rs.MoveFirst
    47. rs!Name = Text1.Text
    48. rs!grade = Text2.Text
    49. End Sub
    50.  
    51. Private Sub Command7_Click()
    52. Data1.rs.MoveNext
    53. If Data1.rs.EOF Then
    54. Data1.rs.MoveFirst
    55. rs!Name = Text1.Text
    56. rs!grade = Text2.Text
    57. End If
    58. End Sub
    59.  
    60. Private Sub Command8_Click()
    61. Data1.rs.MoveLast
    62. rs!Name = Text1.Text
    63. rs!grade = Text2.Text
    64. End Sub
    65.  
    66. Private Sub form_Load()
    67. Set db = OpenDatabase("C:\Documents and Settings\Administrator\My Documents\studentdatabase.mdb")
    68. Set rs = db.OpenRecordset("studentdatabase", dbOpenDynaset)
    69. If Not rs.EOF Then rs.MoveFirst
    70. End Sub
    71.  
    72. Private Sub Label1_Click()
    73. Label1.Caption = rs!Name
    74. rs.MoveNext
    75. End Sub
    76.  
    77. Private Sub Label2_Click()
    78. Label2.Caption = rs!grade
    79. rs.MoveNext
    80. End Sub






    Edit: Added [vbcode][/vbcode] tags for clarity. - Hack
    Last edited by Hack; Nov 7th, 2005 at 07:24 AM.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: DOA Problem! Plz Help Me Out!

    You have changed "Data1.Recordset" to "Data1.rs", what you should have done is change
    "Data1.Recordset" to "rs"

    The labels (when clicked) will show the value of the fields, which should be the same as was shown in the textboxes (when the record was first shown).


    ps: when you post code, please paste it inside VBCode tags, eg:

    [vbcode]'Your code here[/vbcode]

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    7

    Re: DOA Problem! Plz Help Me Out!

    i am still having some problems while running it...it is not giving me right output...plz plz can any1 look into my code and tell me whats wrong with it...ive done everything ..ive tried everything....don't know whats wrong with the code?

    VB Code:
    1. Dim db As Database
    2. Dim rs As Recordset
    3.  
    4. Private Sub Command1_Click()
    5. rs.AddNew
    6. Text1.Text = ""
    7. Text2.Text = ""
    8. rs.Update
    9. End Sub
    10.  
    11. Private Sub Command2_Click()
    12. Text1.Text = ""
    13. Text2.Text = ""
    14. rs.Delete
    15. End Sub
    16.  
    17. Private Sub Command3_Click()
    18. If rs.EOF Then
    19. rs.AddNew
    20. Else
    21. rs.Edit
    22. End If
    23. rs!Name = Text1.Text
    24. rs!grade = Text2.Text
    25. rs.Update
    26. End Sub
    27.  
    28. Private Sub Command4_Click()
    29. rs.Edit
    30. rs!Name = Text1.Text
    31. rs!grade = Text2.Text
    32. rs.Update
    33. End Sub
    34.  
    35. Private Sub Command5_Click()
    36. rs.MoveFirst
    37. Text1.Text = rs!Name
    38. Text2.Text = rs!grade
    39. End Sub
    40.  
    41. Private Sub Command6_Click()
    42. rs.MovePrevious
    43. If Not rs.BOF Then
    44. Text1.Text = rs!Name
    45. Text2.Text = rs!grade
    46. End If
    47. If rs.BOF = True Then
    48. Command6.Enabled = False
    49. End If
    50. End Sub
    51.  
    52. Private Sub Command7_Click()
    53. rs.MoveNext
    54. If Not rs.EOF Then
    55. Text1.Text = rs!Name
    56. Text2.Text = rs!grade
    57. End If
    58. If rs.EOF = True Then
    59. Command7.Enabled = False
    60. End If
    61. End Sub
    62.  
    63. Private Sub Command8_Click()
    64. rs.MoveLast
    65. Text1.Text = rs!Name
    66. Text2.Text = rs!grade
    67. End Sub
    68.  
    69. Private Sub Form_Load()
    70. Set db = OpenDatabase("c:\documents and settings\administrator\my documents\education.mdb")
    71. Set rs = db.OpenRecordset("select*from student")
    72. rs.MoveFirst
    73. Text1.Text = rs!Name
    74. Text2.Text = rs!grade
    75. End Sub

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    7

    Re: DOA Problem! Plz Help Me Out!

    i have tried to modify the code again so...in the above post ...the modifications symmbolize this:--here command1 is for the ADD command button, command2 is for the DELETE command button, command 3 is for the EDIT command button , command4 is for the UPDATE command button,command5 is for moving FIRST command button,command 6 is fo moving PREVIOUS command button, command7 is for moving NEXT command button, command8 is for moving LAST command button.

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: DOA Problem! Plz Help Me Out!

    So, what is happening, or not happening, now?

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: DOA Problem! Plz Help Me Out!

    The only obvious problem I can see is Command1, which should be like this:
    VB Code:
    1. Private Sub Command1_Click()
    2. rs.AddNew
    3. rs!Name = Text1.Text
    4. rs!grade = Text2.Text
    5. rs.Update
    6. End Sub

  9. #9

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    7

    Re: DOA Problem! Plz Help Me Out!

    here is my code again which is working fine for all the move first,last,previous and next buttons...but i don't know why is it not showing me the correct results for adding a new record(it shows a msg "record updated",without asking a user anything about adding a new record),updating,editing and deleting the record...can any 1 of u plz fix this code of mine....it is showing some strange errors which im not able to find out...here is the code...
    VB Code:
    1. Dim db As Database
    2. Dim rs As Recordset
    3.  
    4. Private Sub Command1_Click()
    5. rs.MoveFirst                             //first command button
    6. display
    7. End Sub
    8.  
    9. Private Sub Command2_Click()
    10. On Error GoTo error:
    11. rs.MovePrevious                                  //previous command button
    12. If Not rs.BOF Then
    13. display
    14. Exit Sub
    15. Else: MsgBox ("that was the first record")
    16. End If
    17. error:
    18. MsgBox error.Description
    19. End Sub
    20.  
    21. Private Sub Command3_Click()
    22. On Error GoTo error1:
    23. rs.MoveNext
    24. If Not rs.EOF Then                                      //next command button
    25. display
    26. Exit Sub
    27. Else: MsgBox ("that was the last record")
    28. End If
    29. error1:
    30. MsgBox error.Description
    31. End Sub
    32.  
    33. Private Sub Command4_Click()
    34. rs.MoveLast                                            //last command button
    35. display
    36. End Sub
    37.  
    38. Private Sub Command5_Click()
    39. rs.AddNew
    40. rs!Name = Text1.Text
    41. rs!grade = Text2.Text
    42. rs.Update                                            //adding a new record
    43. MsgBox "record updated"
    44. End Sub
    45.  
    46.  
    47.  
    48.  
    49.  
    50.  
    51. Private Sub Command8_Click()
    52. rs.Edit
    53. rs!Name = Text1.Text
    54. rs!grade = Text2.Text                               //updating a record
    55. rs.Update
    56. End Sub
    57.  
    58. Private Sub Form_Load()
    59. Set db = OpenDatabase("c:\documents and settings\administrator\my documents\namegradeinfo.mdb")
    60. Set rs = db.OpenRecordset("select*from namegrade")
    61. rs.Move First
    62. display
    63. End Sub
    64. Function display()
    65. Text1.Text = rs!Name
    66. Text2.Text = rs!grade
    67. End Function
    Any help would be much appreciated!

  10. #10
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: DOA Problem! Plz Help Me Out!

    BTW: It DAO not DOA. DOA is Dead on Arrival...

  11. #11
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: DOA Problem! Plz Help Me Out!

    Quote Originally Posted by galmca
    here is my code again which is working fine for all the move first,last,previous and next buttons...but i don't know why is it not showing me the correct results for adding a new record(it shows a msg "record updated",without asking a user anything about adding a new record),updating,editing and deleting the record...can any 1 of u plz fix this code of mine....it is showing some strange errors which im not able to find out...here is the code...
    You want to ask the user if he wants to add new record or not?

    VB Code:
    1. Private Sub Command5_Click()
    2.     If MsgBox("Do you want to add new record?   ", vbQuestion + vbYesNo, "Confirm") = vbYes Then
    3.         rs.AddNew
    4.         rs!Name = Text1.Text
    5.         rs!grade = Text2.Text
    6.         rs.Update                                            '//adding a new record
    7.         MsgBox "record updated"
    8.     End If
    9. End Sub

    What kind of errors are you encountering? Post the error descriptions and on what line do they occur...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  12. #12

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    7

    Re: DOA Problem! Plz Help Me Out!

    what error it is giving me is that basically it is showing that when i click on add new record then it doesn't empty the text boxes and clicking on add new record it asks do u want to add new record when i click on yes..instead of emptying the textboxes and asking users to enter something in them.it just displays a msg "record updated".even before taking anything from the user.why it is happening like that?also can u plz tell me what should the coding be like in edit,update and delete section for them to run properly.? plz help me out...ive been stuck in this problem for so long now...

  13. #13
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: DOA Problem! Plz Help Me Out!

    Quote Originally Posted by galmca
    what error it is giving me is that basically it is showing that when i click on add new record then it doesn't empty the text boxes and clicking on add new record it asks do u want to add new record when i click on yes..instead of emptying the textboxes and asking users to enter something in them.it just displays a msg "record updated".even before taking anything from the user.why it is happening like that?also can u plz tell me what should the coding be like in edit,update and delete section for them to run properly.? plz help me out...ive been stuck in this problem for so long now...
    Are your textboxes bounded? Perhaps in a command button labeled "New" you will ask the user if he/she wants to add a new record, if yes then just empty the textboxes, then in a command button labeled "Save" you will do then actual adding of new records...

    Here's a simple example...

    VB Code:
    1. Private Sub Add()
    2.     If MsgBox("Do you want to add?   ", vbExclamation + vbYesNo, "Confirm") = vbYes Then
    3.         Text1.Text = vbNullString
    4.         Text2.Text = vbNullString
    5.         Text1.SetFocus
    6.     End If
    7. End Sub
    8.  
    9. Private Sub Save()
    10.     If MsgBox("Do you want to save?   ", vbQuestion + vbYesNo, "Confirm") = vbYes Then
    11.         rs.AddNew
    12.         rs!Name = Text1.Text
    13.         rs!grade = Text2.Text
    14.         rs.Update                                            '//adding a new record
    15.         MsgBox "record updated"
    16.     End If
    17. End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  14. #14

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    7

    Re: DOA Problem! Plz Help Me Out!

    thanks...now with ur help ,my add command button is working now but now although i know that what should be done for the delete command button ..that is by using rs.delete..but somehow it is not giving me the desired output..so can u plz plz tell me what should be the correct lines of code for delete,edit and update command buttons?
    for delete,would i have to use 2 events also,like 1 for emptying the current record and then the second 1 for actual deleting purpose?i am confused,that what policy should be taken up,here for deleting a required record? if i can understand that...then i would be able to understand the whole DAO concept..so plz help me out in making me understand about these 3 command buttons ,specially the edit and update command buttons/ and delete too...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width