Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Adding record to Access

Posted on 2003-03-16
9
Medium Priority
?
153 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
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
Independent Software Vendors: 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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

580 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