13 Replies - 998 Views - Last Post: 13 August 2009 - 12:20 PM Rate Topic: -----

#1 MEO  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 07-August 09

Adding Record though ADO Causing Error

Post icon  Posted 07 August 2009 - 04:16 PM

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
Is This A Good Question/Topic? 0
  • +

Replies To: Adding Record though ADO Causing Error

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 1949
  • View blog
  • Posts: 8,672
  • Joined: 29-May 08

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: :code:

Thanks.
Was This Post Helpful? 0
  • +
  • -

#3 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 172
  • View blog
  • Posts: 1,560
  • Joined: 17-April 07

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
Was This Post Helpful? 0
  • +
  • -

#4 MEO  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 07-August 09

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
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 

Was This Post Helpful? 0
  • +
  • -

#5 Nikhil_07n  Icon User is offline

  • The cheese stands alone..
  • member icon

Reputation: 48
  • View blog
  • Posts: 2,489
  • Joined: 09-January 09

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.
Was This Post Helpful? 0
  • +
  • -

#6 birdflu9999  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 26
  • Joined: 26-June 09

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.

This post has been edited by birdflu9999: 08 August 2009 - 12:22 PM

Was This Post Helpful? 0
  • +
  • -

#7 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 172
  • View blog
  • Posts: 1,560
  • Joined: 17-April 07

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

Was This Post Helpful? 0
  • +
  • -

#8 MEO  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 07-August 09

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
Was This Post Helpful? 0
  • +
  • -

#9 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 172
  • View blog
  • Posts: 1,560
  • Joined: 17-April 07

Re: Adding Record though ADO Causing Error

Posted 09 August 2009 - 06:27 PM

see my previous post, its the solution for you
Was This Post Helpful? 0
  • +
  • -

#10 MEO  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 07-August 09

Re: Adding Record though ADO Causing Error

Posted 11 August 2009 - 11:24 AM

Attached File  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)


Was This Post Helpful? 0
  • +
  • -

#11 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 172
  • View blog
  • Posts: 1,560
  • Joined: 17-April 07

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


	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
Was This Post Helpful? 0
  • +
  • -

#12 MEO  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 07-August 09

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
Was This Post Helpful? 0
  • +
  • -

#13 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 172
  • View blog
  • Posts: 1,560
  • Joined: 17-April 07

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
Was This Post Helpful? 0
  • +
  • -

#14 MEO  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 07-August 09

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1