|
-
Nov 5th, 2005, 12:28 PM
#1
Thread Starter
New Member
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:
Dim db As Database
Dim rs As Recordset
Private Sub Command1_Click()
rs.AddNew
Text1.Text = "" //add new record command button
Text2.Text = ""
rs.Update
End Sub
Private Sub Command2_Click()
If rs.EOF Then
rs.AddNew
Else
rs.Edit
End If
rs!Name = Text1.Text //edit record command button
rs!grade = Text2.Text
rs.Update
End Sub
Private Sub Command3_Click()
Text1.Text = ""
Text2.Text = "" //delete record command button
rs.Delete
End Sub
Private Sub Command4_Click()
rs.Edit
rs!Name = Text1.Text
rs!grade = Text2.Text //update database
rs.Update
End Sub
Private Sub Command5_Click()
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then // move previous command button
Data1.Recordset.MoveLast
End If
End Sub
Private Sub Command6_Click()
Data1.Recordset.MoveFirst //move first command button
End Sub
Private Sub Command7_Click()
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then //move next command button
Data1.Recordset.MoveFirst
End If
End Sub
Private Sub Command8_Click()
Data1.Recordset.MoveLast //move last command button
End Sub
Private Sub form_Load()
Set db = OpenDatabase("C:\Documents and Settings\Administrator\My Documents\studentdatabase.mdb")
Set rs = db.OpenRecordset("studentdatabase", dbOpenDynaset)
If Not rs.EOF Then rs.MoveFirst
End Sub
Private Sub Label1_Click()
Char Name = rs!Name
rs.MoveNext
End Sub
Private Sub Label2_Click()
Char grade = rs!grade
rs.MoveNext
End Sub
Last edited by si_the_geek; Nov 5th, 2005 at 04:40 PM.
Reason: added VBCode tags
-
Nov 5th, 2005, 04:49 PM
#2
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:
rs!Name = Text1.Text
rs!grade = Text2.Text
Also, I'm a bit confused, what are these two lines about?
VB Code:
Char Name = rs!Name
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:
Label1.Caption = rs!Name
Label2.Caption = rs!grade
-
Nov 6th, 2005, 09:24 PM
#3
Thread Starter
New Member
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:
Dim db As Database
Dim rs As Recordset
Private Sub Command1_Click()
rs.AddNew
Text1.Text = ""
Text2.Text = ""
rs.Update
End Sub
Private Sub Command2_Click()
If rs.EOF Then
rs.AddNew
Else
rs.Edit
End If
rs!Name = Text1.Text
rs!grade = Text2.Text
rs.Update
End Sub
Private Sub Command3_Click()
Text1.Text = ""
Text2.Text = ""
rs.Delete
End Sub
Private Sub Command4_Click()
rs.Edit
rs!Name = Text1.Text
rs!grade = Text2.Text
rs.Update
End Sub
Private Sub Command5_Click()
Data1.rs.MovePrevious
If Data1.rs.BOF Then
Data1.rs.MoveLast
rs!Name = Text1.Text
rs!grade = Text2.Text
End If
End Sub
Private Sub Command6_Click()
Data1.rs.MoveFirst
rs!Name = Text1.Text
rs!grade = Text2.Text
End Sub
Private Sub Command7_Click()
Data1.rs.MoveNext
If Data1.rs.EOF Then
Data1.rs.MoveFirst
rs!Name = Text1.Text
rs!grade = Text2.Text
End If
End Sub
Private Sub Command8_Click()
Data1.rs.MoveLast
rs!Name = Text1.Text
rs!grade = Text2.Text
End Sub
Private Sub form_Load()
Set db = OpenDatabase("C:\Documents and Settings\Administrator\My Documents\studentdatabase.mdb")
Set rs = db.OpenRecordset("studentdatabase", dbOpenDynaset)
If Not rs.EOF Then rs.MoveFirst
End Sub
Private Sub Label1_Click()
Label1.Caption = rs!Name
rs.MoveNext
End Sub
Private Sub Label2_Click()
Label2.Caption = rs!grade
rs.MoveNext
End Sub
Edit: Added [vbcode][/vbcode] tags for clarity. - Hack
Last edited by Hack; Nov 7th, 2005 at 07:24 AM.
-
Nov 6th, 2005, 09:32 PM
#4
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]
-
Nov 15th, 2005, 06:26 AM
#5
Thread Starter
New Member
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:
Dim db As Database
Dim rs As Recordset
Private Sub Command1_Click()
rs.AddNew
Text1.Text = ""
Text2.Text = ""
rs.Update
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
rs.Delete
End Sub
Private Sub Command3_Click()
If rs.EOF Then
rs.AddNew
Else
rs.Edit
End If
rs!Name = Text1.Text
rs!grade = Text2.Text
rs.Update
End Sub
Private Sub Command4_Click()
rs.Edit
rs!Name = Text1.Text
rs!grade = Text2.Text
rs.Update
End Sub
Private Sub Command5_Click()
rs.MoveFirst
Text1.Text = rs!Name
Text2.Text = rs!grade
End Sub
Private Sub Command6_Click()
rs.MovePrevious
If Not rs.BOF Then
Text1.Text = rs!Name
Text2.Text = rs!grade
End If
If rs.BOF = True Then
Command6.Enabled = False
End If
End Sub
Private Sub Command7_Click()
rs.MoveNext
If Not rs.EOF Then
Text1.Text = rs!Name
Text2.Text = rs!grade
End If
If rs.EOF = True Then
Command7.Enabled = False
End If
End Sub
Private Sub Command8_Click()
rs.MoveLast
Text1.Text = rs!Name
Text2.Text = rs!grade
End Sub
Private Sub Form_Load()
Set db = OpenDatabase("c:\documents and settings\administrator\my documents\education.mdb")
Set rs = db.OpenRecordset("select*from student")
rs.MoveFirst
Text1.Text = rs!Name
Text2.Text = rs!grade
End Sub
-
Nov 15th, 2005, 06:32 AM
#6
Thread Starter
New Member
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.
-
Nov 15th, 2005, 08:28 AM
#7
Re: DOA Problem! Plz Help Me Out!
So, what is happening, or not happening, now?
-
Nov 15th, 2005, 12:05 PM
#8
Re: DOA Problem! Plz Help Me Out!
The only obvious problem I can see is Command1, which should be like this:
VB Code:
Private Sub Command1_Click()
rs.AddNew
rs!Name = Text1.Text
rs!grade = Text2.Text
rs.Update
End Sub
-
Nov 24th, 2005, 05:30 PM
#9
Thread Starter
New Member
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:
Dim db As Database
Dim rs As Recordset
Private Sub Command1_Click()
rs.MoveFirst //first command button
display
End Sub
Private Sub Command2_Click()
On Error GoTo error:
rs.MovePrevious //previous command button
If Not rs.BOF Then
display
Exit Sub
Else: MsgBox ("that was the first record")
End If
error:
MsgBox error.Description
End Sub
Private Sub Command3_Click()
On Error GoTo error1:
rs.MoveNext
If Not rs.EOF Then //next command button
display
Exit Sub
Else: MsgBox ("that was the last record")
End If
error1:
MsgBox error.Description
End Sub
Private Sub Command4_Click()
rs.MoveLast //last command button
display
End Sub
Private Sub Command5_Click()
rs.AddNew
rs!Name = Text1.Text
rs!grade = Text2.Text
rs.Update //adding a new record
MsgBox "record updated"
End Sub
Private Sub Command8_Click()
rs.Edit
rs!Name = Text1.Text
rs!grade = Text2.Text //updating a record
rs.Update
End Sub
Private Sub Form_Load()
Set db = OpenDatabase("c:\documents and settings\administrator\my documents\namegradeinfo.mdb")
Set rs = db.OpenRecordset("select*from namegrade")
rs.Move First
display
End Sub
Function display()
Text1.Text = rs!Name
Text2.Text = rs!grade
End Function
Any help would be much appreciated!
-
Nov 24th, 2005, 05:41 PM
#10
Re: DOA Problem! Plz Help Me Out!
BTW: It DAO not DOA. DOA is Dead on Arrival...
-
Nov 24th, 2005, 08:00 PM
#11
Re: DOA Problem! Plz Help Me Out!
 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:
Private Sub Command5_Click()
If MsgBox("Do you want to add new record? ", vbQuestion + vbYesNo, "Confirm") = vbYes Then
rs.AddNew
rs!Name = Text1.Text
rs!grade = Text2.Text
rs.Update '//adding a new record
MsgBox "record updated"
End If
End Sub
What kind of errors are you encountering? Post the error descriptions and on what line do they occur...
-
Nov 25th, 2005, 04:49 PM
#12
Thread Starter
New Member
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...
-
Nov 25th, 2005, 08:09 PM
#13
Re: DOA Problem! Plz Help Me Out!
 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:
Private Sub Add()
If MsgBox("Do you want to add? ", vbExclamation + vbYesNo, "Confirm") = vbYes Then
Text1.Text = vbNullString
Text2.Text = vbNullString
Text1.SetFocus
End If
End Sub
Private Sub Save()
If MsgBox("Do you want to save? ", vbQuestion + vbYesNo, "Confirm") = vbYes Then
rs.AddNew
rs!Name = Text1.Text
rs!grade = Text2.Text
rs.Update '//adding a new record
MsgBox "record updated"
End If
End Sub
-
Nov 26th, 2005, 10:14 AM
#14
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|