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_Number") = txtCarFleetNumber.Text
    AdodcHire.Recordset.Fields("Date_Out") = txtDateOut.Text
    AdodcHire.Recordset.Fields("Date_Return") = 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
katadeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JoaTexCommented:
Hi

maybe the pointer to your database is incorrect. Try This

AdocHire.Databasename = "your database name.mdb"
AdocHire.RecordSource = "Your Table Name"
AdocHire.Recordset.MoveLast
AdodcHire.Recordset.AddNew
   AdodcHire.Recordset.Fields("Customer_Number") = txtCustNumber.Text
   AdodcHire.Recordset.Fields("Fleet_Number") = txtCarFleetNumber.Text
   AdodcHire.Recordset.Fields("Date_Out") = txtDateOut.Text
   AdodcHire.Recordset.Fields("Date_Return") = dtpDateDue
   AdodcHire.Recordset.Fields("Mileage_Out") = txtMileageOut.Text
   AdodcHire.UpdateRecord

Jo
0
perezmCommented:
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
0
y2kswCommented:
Use:

... = IIf(Len(Text1.Text), Text1.Text, Null)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Mayank SAssociate Director - Product EngineeringCommented:
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.
0
CleanupPingCommented:
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?
0
GPrentice00Commented:
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:
http://www.experts-exchange.com/help/closing.jsp

GPrentice00
Cleanup Volunteer
0
Mayank SAssociate Director - Product EngineeringCommented:
Probably he's got the solution and that's why he's not reverting back. Anything you do will be binding with me, GPrentice00.
0
GPrentice00Commented:
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
0
YensidModCommented:
Question is PAQ'd and no points refunded.

YensidMod
Community Support Moderator @Experts Exchange
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.