A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Links and Linking
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

populating data from excel into access



 
 
Thread Tools Display Modes
  #1  
Old December 13th, 2004, 02:45 PM
Chris
external usenet poster
 
Posts: n/a
Default populating data from excel into access

I have a excel user form that collects data and then drops it into an access
table. However if the user doesn't complete a field or leaves a field blank
then the code comes back with an error.



Dim db As DAO.Database
Set db = DAO.OpenDatabase("accessdatabase.mdb")
' Open the table
Dim rs As DAO.Recordset
Set rs = db.OpenRecordset("tblFOI")

' Write the data
rs.AddNew
rs!area = area_cbo.Text
rs!Officer = officer_txt.Text
rs!tel = tel_txt.Text
rs!Type = type_cbo.Text
rs!firstname = firstname_txt.Text
rs!lastname = lastname_txt.Text
rs!street = street_txt.Text
rs!town = town_txt.Text
rs!county = county_txt.Text
rs!postcode = postcode_txt.Text
rs!apptel = apptel_txt.Text
rs!fax = fax_txt.Text
rs!email = email_txt.Text
rs!Method = method_cbo.Text
rs!request = request_cbo.Text
rs!Description = description_txt.Text
rs!payment = payment_txt.Text
rs!methodreceived = methodreceived_cbo.Text
rs!datetohq = datetohq_txt.Text
rs!target = target_txt.Text
rs!sent = sent_txt.Text
rs!reasons = reasons_txt.Text


' Update the table
rs.Update
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing

Any Ideas???

  #2  
Old December 15th, 2004, 07:50 AM
Bill Manville
external usenet poster
 
Posts: n/a
Default

Chris wrote:
if the user doesn't complete a field or leaves a field blank
then the code comes back with an error.


Would help to know what the error was.
I am guessing that you were trying to feed a zero length string into a
table field that is set to not allow zero length strings.

If that is the case and the fields have no default value specified then

' leave Null if no value specified
if area_cbo.Text"" Then rs!area = area_cbo.Text
if officer_txt.Text"" Then rs!Officer = officer_txt.Text
'etc

Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - respond to newsgroup

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Access To Excel: Data Transfer HatesTheCold General Discussion 5 January 7th, 2005 10:17 PM
Accessing Excel to import Data into Access via ADO Peter Neumaier General Discussion 1 September 7th, 2004 10:46 AM
Adding staff photographs to my database KK New Users 2 September 3rd, 2004 07:41 AM
Excel VBA-Geting data from Access kodricales New Users 2 May 27th, 2004 09:23 PM
Linking Excel data through Access to use a Form as an Interface Laura Links and Linking 0 March 23rd, 2004 03:59 PM


All times are GMT +1. The time now is 01:36 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.