Solved

inserting date into a table with visual basic

Posted on 2003-10-23
22
577 Views
Last Modified: 2013-11-25
hello,
I want to insert the date into a table with visual basic, i defined the date column to be Date type, I want to take the date from the machine by using Now() function that returns both date and time, I tried using Format function to get only the date:  Format (Now, "short date") but I got the following compiler error: "Can't find project or library"
which library do I need to inlude in order to use this function?
thanx.
0
Comment
Question by:zolpo
  • 8
  • 5
  • 4
  • +4
22 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 9606414
Hi zolpo,

What database are you using, for access it would be something like:

"Insert Into MyTable MyField,MyDateField Values('My Value',#" & Format(Now(),"yyyy-mm-dd") & "#)"

For MS SQL it would be

"Insert Into MyTable MyField,MyDateField Values('My Value','" & Format(Now(),"yyyy-mm-dd") & "')"

Tim Cottee MCSD, MCDBA, CPIM
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 
LVL 5

Expert Comment

by:rajaamirapu
ID: 9606493
Go to Project references and see wheather there any missing libararys/DLLS/TLBS in your project.Include the missing libararys and then complie this solves your problem
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 9606529
As a note, the reason for using yyyy-mm-dd rather than short date is a simple one, especially if you are using MS Access. yyyy-mm-dd gives you effectively an unambiguous date format that will always be correctly interpreted when it is stored. MS Access is peculiar in that it will *ONLY* accept dates when they are passed in the american format mm/dd/yy regardless of the locale short date or long date setting. This can cause significant confusion and complication if you do not allow for it in this way.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 1

Author Comment

by:zolpo
ID: 9606644
TimCottee, Thanks for your replay!
I wrote the query as u said, but my problem was the compiler error I got when using the Format function,
I'm using visual basic enterprise edition with Access 97,
the compiler gives the error on the following line i wrote:
hour = Format (Now, "short date") and marks the word "Format", the error i get is a run time error, "Compiler error : can't find project or library"
thanx

0
 
LVL 5

Expert Comment

by:rajaamirapu
ID: 9606674
Go to Project references and see wheather there any missing libararys/DLLS/TLBS in your project.Include the missing libararys  
0
 
LVL 1

Expert Comment

by:s_sarigul
ID: 9606724
That's the SQL

STSQL="Insert Into <TABLE> (First_Date) Values(CDATE( ' "+Cstr(Date)+" ' ))"
 
0
 
LVL 1

Author Comment

by:zolpo
ID: 9606763
rajaamirapu thanks,
what libraries do i need to include in order to use Format function???
(I searched the web for examples of using format function but non of them used any include)
0
 
LVL 5

Expert Comment

by:rajaamirapu
ID: 9606775
Any libraries are missing in the references it will show the missing ones with missing:librarary name.
0
 
LVL 5

Expert Comment

by:rajaamirapu
ID: 9606781
in the references dialog.
0
 
LVL 1

Author Comment

by:zolpo
ID: 9606851
rajaamirapu,
I looked at the project refrences the missing libraries are:
Missing: Microsoft DAO 3.6 Object library
Missing: Microsoft activeX data objects (multi dimensional).....
I dont think that these libraries are connected to my problem,
however,
the library: Microsoft data formatting object is NOT missing, that's the library (I think) I need to use Format()
thanks
0
 
LVL 5

Expert Comment

by:rajaamirapu
ID: 9606874
Include those libraries and see
Missing: Microsoft DAO 3.6 Object library
Missing: Microsoft activeX data objects (multi dimensional).....
This is because VB 6.0 will show complie error like that only.I had this problem before and i solved it by including those
Thanks
0
 
LVL 5

Expert Comment

by:rajaamirapu
ID: 9606892
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 250 total points
ID: 9606975
Your problem is with VBA.dll, some is corrupted or missing, maybe you have installed some new stuff recently. Try to locate that dll from your office installation, after that, unregister that dll, delete from the system, copy new one and re-register it.
0
 
LVL 5

Expert Comment

by:rajaamirapu
ID: 9607010
Is the version of Microsoft activeX data objects (multi dimensional) is 2.5?
0
 
LVL 1

Author Comment

by:zolpo
ID: 9607968
rajaamirapu
nope, it's 2.6
thanks
0
 
LVL 5

Assisted Solution

by:rajaamirapu
rajaamirapu earned 250 total points
ID: 9608065
Include Microsoft activeX data objects (multi dimensional) is 2.6 and try
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9608685
"....
hour = Format (Now, "short date") and marks the word "Format", the error i get is a run time error, "Compiler error : can't find project or library"
...."
Format function is included in VBA.dll (As all other string functions)
Cheers
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9608691
Also Now(), by the way.
0
 

Expert Comment

by:gherme
ID: 9609853
Hi
You can get the date using Date function (dd-mm-yyyy) then use the format
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9609897
Date function belongs to VBA.dll too.
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9613588
Is any reason you have include another reference that has format in

try to use

hour = VBA.Format (Now, "short date")
0
 
LVL 1

Author Comment

by:zolpo
ID: 9622235
Thanks You All !
the problem was with the installation,
I re-install some stuff and it worked.
Thanks again
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Basic Excel Formatting error 4 102
VBA: Personal Macro Retain/Highlight/Remove values in a selected column 4 29
SSRS troubles 4 46
Where did System.Data.Objects go? 2 23
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now