Problem with SQL

P

PaleRider

Hi,

I keep getting a "Too few parameters. Expected 1." error when I try to
insert a value into a field in table Main. What I want to do is insert the
value of lngCount into a field named DaysRemaining but only if the value in
field named IsExpired is equal to -1. Can someone figure out how to fix the
sql string so Access will be happy. Thanks in advance...

Here's my code:

dim lngCount as Long
dim strSql as String

lngCount = DateDiff("d", Date(), Me.txtExpiredDate)


strSql = "UPDATE Main SET Main.DaysRemaining = lngCount " & "WHERE
(((Main.IsExpired) = true));"

CurrentDb.Execute strSql
 
C

Clifford Bass

Hi,

You need to move the lngCount so it is outside of the quoted stuff.
Also you can simplify the whole thing to one statement:

CurrentDb.Execute _
"UPDATE Main " & _
"SET DaysRemaining = " & DateDiff("d", Date(), txtExpiredDate) & " " & _
"WHERE IsExpired"

Clifford Bass
 
P

PaleRider

Clifford,

I still get the "Too few parameters" error but I can't tell what is missing.

-PR
 
P

PaleRider

Clifford,

How about I remove a field. Can you show me how to insert the value 8 into
a field using SQL if I had this:

Table Name = Main
Field Name = DaysRemaining
Variable Name = lngCount
Value of lngCount = 8
 
P

PaleRider

Clifford,

I was able to figure out how to make it work. Thanks for your help and reply.
 
C

Clifford Bass

Hi,

Good to hear you solved it before I was able to see your replies.

You are welcome,

Clifford Bass
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top