Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

populate table 1

Status
Not open for further replies.

vttech

Technical User
Jan 28, 2006
297
US
I am trying to create a procedure that will populate a table with dates. The code is listed below
When I run the procedure I get

Compile error:

Invalid outside procedure


and debug brings me to this line

SDate = "5/20/2006"


Code:
Option Explicit

Dim SDate As Date
Dim EDate As Date
Dim sqlstr As String

SDate = "5/20/2006"
EDate = "6/30/2007"


Public Sub PayPeriods()
Do While (SDate < EDate)
sqlstr = "insert into tblPayPeriod (" & StartDate & ")" & "values (" & SDate & ")"

DoCmd.RunSQL sqlstr

SDate = DateAdd("d", 14, SDate)
Loop
End Sub

Can someone tell be what I am doing wrong and if this code will achieve my goal?

Newbie in search of knowledge
 
Ok I change the code and everthing seems to work
the debug.print shows

insert into tblPayPeriod (StartDate)values (6/3/2006)
insert into tblPayPeriod (StartDate)values (6/17/2006)
insert into tblPayPeriod (StartDate)values (7/1/2006)
insert into tblPayPeriod (StartDate)values (7/15/2006)
insert into tblPayPeriod (StartDate)values (7/29/2006)
etc...


but when I look in the table I see entries like


StartDate
12:00:11 AM
12:01:26 AM
12:00:15 AM
12:05:01 AM
12:00:20 AM
12:00:10 AM
12:00:29 AM
12:00:13 AM
12:00:43 AM


why am I getting those results??


Code:
Option Compare Database
Option Explicit

Public EmployeeID As Integer

Dim SDate As Date
Dim EDate As Date
Dim sqlstr As String


Public Sub PayPeriods()
SDate = "5/20/2006"
EDate = "6/30/2007"

Do While (SDate < EDate)
sqlstr = "insert into tblPayPeriod (StartDate)" & "values (" & SDate & ")"

Debug.Print sqlstr

'DoCmd.RunSQL sqlstr

SDate = DateAdd("d", 14, SDate)
Loop
End Sub

Newbie in search of knowledge
 
Dates need hash marks (#):

"insert into tblPayPeriod (StartDate) " & "values (#" & SDate & "#)"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top