I am getting no error codes it is just only putting a single record
into the database. Could we still have a problem with the primary key
because the DateReequested is the same also? Do I need a primary key?
Jeff L wrote:
Your VisitorID is a number and thus your don't want the single quotes
around it when you are inserting it. It should be
DoCmd.RunSQL "Insert Into [Suffolk Visitor Parking Log] " & _
"Values(" & Me.VisitorID & ", '" & Me.DateRequested + I & "');"
If you are getting any error messages, it would be helpful if you
could
post it with your response.
Fred wrote:
I have figured out the multilpe keys but still no luck I am posting
the
script again in case I have messed it up. Thanx Fred
Private Sub DaysBetween_Click()
Dim DaysBetween As Integer, I As Integer
DaysBetween = DateDiff("d", Me.DateRequested, Me.DepartureDate)
For I = 0 To DaysBetween
DoCmd.RunSQL "Insert Into [Suffolk Visitor Parking Log] " & _
"Values('" & Me.VisitorID & "', '" & Me.DateRequested + I & "');"
Next I
End Sub
Fred wrote:
Will it work if I have no primary key? How would I go about
making the
primary key VisitorID and DateRequested? Thanx for your help.
Fred
Jeff L wrote:
You cannot insert multiple rows to a table that have the same
primary
key. The primary key must be unique. You could make the key
VisitorId, DateRequested. Having it as VisitorId will only
work for
the first record that you insert, then when you try to insert
the
second record, you will have a duplicate primary key and the
insert
will fail.
Hope that helps!
Fred wrote:
It is not putting the multiple entries in the table and the
primary key
is now VisitorId. It is still putting the one entry in so if
I query on
a date in the in between the dates they need the parking for
it will
not show up. Thanx Fred
Jeff L wrote:
Ok, you say it's not working. What's not working about it?
Are you
getting error messages? Can you tell me what the Primary
Key for your
table, [Suffolk Visitor Parking Log], is?
Fred wrote:
It is still not working and I have already made that
suggestion to the
owner of the database. Here is what I have. Thanx for all
your help
Private Sub DaysBetween_Click()
Dim DaysBetween As Integer, I As Integer
DaysBetween = DateDiff("d", Me.DateRequested,
Me.DepartureDate)
For I = 0 To DaysBetween
DoCmd.RunSQL "Insert Into [Suffolk Visitor Parking Log] "
& _
"Values('" & Me.Lastname & "', '" & Me.DateRequested + I
& "');"
Next I
End Sub
Jeff L wrote:
What you have:
DoCmd.RunSQL "Insert Suffolk Visitor Parking Log" & _
"Values(""& Me.Lastname & "", '" & Me.DateRequested + I
& "');"
What it should be:
DoCmd.RunSQL "Insert Into [Suffolk Visitor Parking Log]
" & _
"Values('"& Me.Lastname & "', '" & Me.DateRequested + I
& "');"
Just curious, but how are you going to distinguish
between people with
the same last name? You should use a unique
identifier, like
VisitorID, to distinguish who your visitors are.
Fred wrote:
Okay I still am fighting this so here is the code I
am using
Private Function DaysBetween()
Dim DaysBetween As Integer, I As Integer
DaysBetween = DateDiff("d", Me.DateRequested,
Me.DepartureDate)
For I = 0 To DaysBetween
DoCmd.RunSQL "Insert Suffolk Visitor Parking Log" & _
"Values(""& Me.Lastname & "", '" & Me.DateRequested +
I & "');"
Next I
End Function
Again thanx for all the help
Jeff L wrote:
When you use a string value like Last Name, you
need to put single
quotes around it. So it's Values('" & Me.LastName
& "',"
Values([SingleQuote][DoubleQuote] &
Me.YourFieldName &
[DoubleQuote][SingleQuote],[DoubleQuote]
When using numeric values, the single quotes are
not needed.
If you are still having trouble, maybe you could
post your code and let
me look at it.
Fred wrote:
I put the code in the Submit command button but
the sql script is
giving me a compile end of statement error. I
have a LastName instead
of a visitor id. It is highlighting the first Me.
I really appreciate
the help Fred
Jeff L wrote:
Probably the best place would be to put it in
the On Click event of a
Command Button. Use the button to make your
parking reservation.