katade
asked on
Adding record to Access
I'm fairly new to VB and I'm having big problems adding a record to my Access DB. I have using the following code: -
'Adds new record to DB
AdodcHire.Recordset.AddNew
AdodcHire.Recordset.Fields ("Customer _Number") = txtCustNumber.Text
AdodcHire.Recordset.Fields ("Fleet_Nu mber") = txtCarFleetNumber.Text
AdodcHire.Recordset.Fields ("Date_Out ") = txtDateOut.Text
AdodcHire.Recordset.Fields ("Date_Ret urn") = dtpDateDue
AdodcHire.Recordset.Fields ("Mileage_ Out") = txtMileageOut.Text
AdodcHire.Recordset.Update
When I run the program I get the following error message "Empty rows cannot be inserted. Rows must have at least one column value set".
I can't understand it, as the values I am passing i.e. txtCustNumber.Text, does exsist. When I debug the error it is stating txtCustNumber is NULL. How can this be?
Please help
'Adds new record to DB
AdodcHire.Recordset.AddNew
AdodcHire.Recordset.Fields
AdodcHire.Recordset.Fields
AdodcHire.Recordset.Fields
AdodcHire.Recordset.Fields
AdodcHire.Recordset.Fields
AdodcHire.Recordset.Update
When I run the program I get the following error message "Empty rows cannot be inserted. Rows must have at least one column value set".
I can't understand it, as the values I am passing i.e. txtCustNumber.Text, does exsist. When I debug the error it is stating txtCustNumber is NULL. How can this be?
Please help
katade,
VB message "Empty rows cannot be inserted. Rows must have at least one column value set" is telling you that your textbox(es) do not contain data.
Your problem is the somewhere in your code, you are removing the data before you can save it. You are going to have to find where you are removing the data from your textbox(es) by stepping through your code.
perezm
VB message "Empty rows cannot be inserted. Rows must have at least one column value set" is telling you that your textbox(es) do not contain data.
Your problem is the somewhere in your code, you are removing the data before you can save it. You are going to have to find where you are removing the data from your textbox(es) by stepping through your code.
perezm
Use:
... = IIf(Len(Text1.Text), Text1.Text, Null)
... = IIf(Len(Text1.Text), Text1.Text, Null)
Try:
' Data1 is a data control object
Data1.DatabaseName = App.Path + "...." ' your .mdb file
Data1.RecordSource = "...." ' table-name
Data1.Refresh
With Data1.Recordset
.AddNew
![Attribute1] = <value>
....
.... ' other attributes
.Update
End With
I think the problem is that there is some attribute which is required but whose values you are not providing in your code. Either edit your Access table in design-view and make that attribute as Not Required, or else provide a value for it through your code.
Mayank.
' Data1 is a data control object
Data1.DatabaseName = App.Path + "...." ' your .mdb file
Data1.RecordSource = "...." ' table-name
Data1.Refresh
With Data1.Recordset
.AddNew
![Attribute1] = <value>
....
.... ' other attributes
.Update
End With
I think the problem is that there is some attribute which is required but whose values you are not providing in your code. Either edit your Access table in design-view and make that attribute as Not Required, or else provide a value for it through your code.
Mayank.
katade:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
Experts: Post your closing recommendations! Who deserves points here?
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
Experts: Post your closing recommendations! Who deserves points here?
This question has been classified as abandoned. I will make a recommendation to the moderators on its resolution in a week or two. I would appreciate any comments by the experts that would help me in making a recommendation.
It is assumed that any participant not responding to this request is no longer interested in its final deposition.
If the asker does not know how to close the question, the options are here:
https://www.experts-exchange.com/help/closing.jsp
GPrentice00
Cleanup Volunteer
It is assumed that any participant not responding to this request is no longer interested in its final deposition.
If the asker does not know how to close the question, the options are here:
https://www.experts-exchange.com/help/closing.jsp
GPrentice00
Cleanup Volunteer
Probably he's got the solution and that's why he's not reverting back. Anything you do will be binding with me, GPrentice00.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
-->PAQ - no points refunded
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER
GPrentice00
Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
-->PAQ - no points refunded
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER
GPrentice00
Cleanup Volunteer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
maybe the pointer to your database is incorrect. Try This
AdocHire.Databasename = "your database name.mdb"
AdocHire.RecordSource = "Your Table Name"
AdocHire.Recordset.MoveLas
AdodcHire.Recordset.AddNew
AdodcHire.Recordset.Fields
AdodcHire.Recordset.Fields
AdodcHire.Recordset.Fields
AdodcHire.Recordset.Fields
AdodcHire.Recordset.Fields
AdodcHire.UpdateRecord
Jo