Hi, Everyone
I made a form for adding new employee, and the problem is when I click add twic the debug message appears to me
Note that the code which I have used is
ado_Employee.Recordset.Addnew
So
What's wrong with me?
best Regards
Adding Record though ADO Causing ErrorVB6
Page 1 of 1
13 Replies - 998 Views - Last Post: 13 August 2009 - 12:20 PM
Replies To: Adding Record though ADO Causing Error
#2
Re: Adding Record though ADO Causing Error
Posted 07 August 2009 - 04:29 PM
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.
Post your code like this:
Thanks.
Post your code like this:
Thanks.
#3
Re: Adding Record though ADO Causing Error
Posted 07 August 2009 - 07:39 PM
you should specify more detail other wise we won't help you
#4
Re: Adding Record though ADO Causing Error
Posted 08 August 2009 - 10:40 AM
When I Click Add Command button twic I get the message that
Run-time error '-2147467259(80004005)
Empty Row connot be inserted.Row must have at least one column value set
and the codes as you asked me
Run-time error '-2147467259(80004005)
Empty Row connot be inserted.Row must have at least one column value set
and the codes as you asked me
Option Explicit Private Sub cmd_AddEmployee_Click() ado_Employee.Recordset.AddNew End Sub Private Sub cmd_Close_Click() Unload Me frm_Employees.Show End Sub Private Sub cmd_Save_Click() If txt_EmployeeLastName.Text = "" And txt_MiddleName.Text = "" And txt_NationalID.Text = "" And txt_Address.Text = "" And txt_HomePhone.Text = "" And txt_FirstName.Text = "" And txt_Title.Text = "" And txt_InsuranceID.Text = "" And txt_City.Text = "" And txt_CellPhone.Text = "" Then MsgBox " you must enter data first " Else ado_Employee.Recordset.Save End If End Sub
#5
Re: Adding Record though ADO Causing Error
Posted 08 August 2009 - 11:10 AM
Oh Well, you are not sending anything from the textboxes to the database.
#6
Re: Adding Record though ADO Causing Error
Posted 08 August 2009 - 12:21 PM
i think what happens is when you click the add button it creates a blank record on your table in the database and if you click the button again it will leave the previous record empty, in that case you are trying to add another record without even entering values from the previous record so this will result in an error because the database won't allow you to create an empty record.
so i suggest that when you click the add button disable it until you save the values you want to enter on your table using this
ado_Employee.Recordset.Update
after saving you just have to enable the add button again.
so i suggest that when you click the add button disable it until you save the values you want to enter on your table using this
ado_Employee.Recordset.Update
after saving you just have to enable the add button again.
This post has been edited by birdflu9999: 08 August 2009 - 12:22 PM
#7
Re: Adding Record though ADO Causing Error
Posted 08 August 2009 - 06:43 PM
check the textboxes datamember and datasource property and also datafield property
This post has been edited by thava: 09 August 2009 - 06:28 PM
#8
Re: Adding Record though ADO Causing Error
Posted 09 August 2009 - 12:40 PM
thank you all
but the logic in programming that If the user click add many times without entering any data the message box would appear for him (you have to insert data first) otherwise the cursor must still on the same record (the last record)
I want to tell the computer that ( if the user click add without entering any data then give him message box then back to the form at the same record(the last record(still as you are)))
Thank you again
but the logic in programming that If the user click add many times without entering any data the message box would appear for him (you have to insert data first) otherwise the cursor must still on the same record (the last record)
I want to tell the computer that ( if the user click add without entering any data then give him message box then back to the form at the same record(the last record(still as you are)))
Thank you again
#9
Re: Adding Record though ADO Causing Error
Posted 09 August 2009 - 06:27 PM
see my previous post, its the solution for you
#10
Re: Adding Record though ADO Causing Error
Posted 11 August 2009 - 11:24 AM
Employee.zip (12.08K)
Number of downloads: 35
I sent you this small database to sent me the correct sequence
thanks a lot
and please don't ask me Thava for more details
because I am the one who need the detail not actually you
bye bye
Attached File(s)
-
Employee.zip (12.08K)
Number of downloads: 42
#11
Re: Adding Record though ADO Causing Error
Posted 11 August 2009 - 06:11 PM
the problem you have is use the OR condition instead of AND
you checked if all textboxes are empty then raise a messagebox else
you save the record
this means if one the textbox has the value then obviously your if condition is false then it goes to the else part and save the record
hope you understand
If txt_EmployeeLastName.Text = "" And txt_MiddleName.Text = "" And txt_NationalID.Text = "" And txt_Address.Text = "" And txt_HomePhone.Text = "" And txt_FirstName.Text = "" And txt_Title.Text = "" And txt_InsuranceID.Text = "" And txt_City.Text = "" And txt_CellPhone.Text = "" Then MsgBox " you must enter data first " Else ado_Employee.Recordset.Save End If
you checked if all textboxes are empty then raise a messagebox else
you save the record
this means if one the textbox has the value then obviously your if condition is false then it goes to the else part and save the record
hope you understand
#12
Re: Adding Record though ADO Causing Error
Posted 12 August 2009 - 12:05 PM
I didn't ask you about save button
I asked you about the Add button
I understand the difference between (and) & (or)
but I am talking about the Add button causing an error when I click it twic
hope you understand
bye bye
I asked you about the Add button
I understand the difference between (and) & (or)
but I am talking about the Add button causing an error when I click it twic
hope you understand
bye bye
#13
Re: Adding Record though ADO Causing Error
Posted 12 August 2009 - 08:04 PM
If ado_Employee.Recordset.EditMode = adEditAdd Or ado_Employee.Recordset.EditMode = adEditInProgress Then ado_Employee.Recordset.CancelUpdate End If ado_Employee.Recordset.AddNew
when you are binding with textboxes it will automatically update the records on the next event that's why the error cause
sorry previously i didn't read your full post
#14
Re: Adding Record though ADO Causing Error
Posted 13 August 2009 - 12:20 PM
thanks forever
I am very happy for that code but as kind of request I want to know how can to get such codes and one more request I want from you to explain this code for me
it is work
but i don't understand
thank you thava
I am very happy for that code but as kind of request I want to know how can to get such codes and one more request I want from you to explain this code for me
it is work
but i don't understand
thank you thava
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|