?
Solved

Adding record to Access

Posted on 2003-03-16
9
Medium Priority
?
152 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:katade
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 2

Expert Comment

by:JoaTex
ID: 8146985
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
 
LVL 1

Expert Comment

by:perezm
ID: 8146988
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
 
LVL 3

Expert Comment

by:y2ksw
ID: 8147622
Use:

... = IIf(Len(Text1.Text), Text1.Text, Null)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:Mayank S
ID: 8149688
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
 

Expert Comment

by:CleanupPing
ID: 8900034
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
 
LVL 6

Expert Comment

by:GPrentice00
ID: 8982957
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 8983500
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
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9033982
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
 

Accepted Solution

by:
YensidMod earned 0 total points
ID: 9126346
Question is PAQ'd and no points refunded.

YensidMod
Community Support Moderator @Experts Exchange
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question