View Full Version : Dates
icthus123
07-13-2007, 05:29 AM
I'd have thought this was a fairly straightforward question.
I'm setting up a database for projects which each in effect run for too years. Therefore next to each one you put eg. 2008-2009, etc. At the moment one column says years start and the other year end. However, I really need this to be in a date format in order to be able to search it properly to get data out, however, I can't put in just a year as a date. Is there anyway for me to do this in access?
Ebrow
07-13-2007, 05:50 AM
You could format each field as "YYYY" and then have an unbound textbox that only allows the user to input 4 digits. When the digits are entered, you could amend the data to 01/01/YYYY and then append to the table.
This way all your dates will be the start of the year and you can then search on it.
I don't know why that would be any better that just making the field numbers with a restriction of 4 digits.
icthus123
07-13-2007, 06:09 AM
You could format each field as "YYYY" and then have an unbound textbox that only allows the user to input 4 digits. When the digits are entered, you could amend the data to 01/01/YYYY and then append to the table.
This way all your dates will be the start of the year and you can then search on it.
I don't know why that would be any better that just making the field numbers with a restriction of 4 digits.
Kool, okay! But I'm not to sure how to go about appending the values?
Ebrow
07-13-2007, 11:15 AM
Try this.
Sub test()
Dim db As Database
Dim mySQL As String
Dim myString As String
myString = "Text"
Set db = CurrentDb()
mySQL = "INSERT INTO tblTest (testField) "
mySQL = "VALUES ('" & myString & "');"
DoCmd.RunSQL (mySQL)
End Sub
Ebrow
07-13-2007, 11:22 AM
for more than one field at a time, seperate them with a comma.
Ebrow
07-13-2007, 11:31 AM
Sub test()
Dim db As Database
Dim mySQL As String
Dim myString As String
myString = "Text"
Set db = CurrentDb()
mySQL = "INSERT INTO tblTest (testField) "
mySQL = mySQl & "VALUES ('" & myString & "');"
DoCmd.RunSQL (mySQL)
End Sub
Sorry for the typo
icthus123
07-16-2007, 01:09 AM
Sub test()
Dim db As Database
Dim mySQL As String
Dim myString As String
myString = "Text"
Set db = CurrentDb()
mySQL = "INSERT INTO tblTest (testField) "
mySQL = mySQl & "VALUES ('" & myString & "');"
DoCmd.RunSQL (mySQL)
End Sub
Sorry for the typo
Sorry Ebrow, but how do I make sure it goes into the right record?
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.