pr2-eugin
Super Moderator
- Local time
- Today, 14:55
- Joined
- Nov 30, 2011
- Messages
- 8,494
Howdy people,
Just a quick question. Let us say you have an action Query as simple as inserting a record with just two fields Name and Date into a table. Just to make it a bit complicated, let us say it needs to be dynamic or in other words need to take the current date and the current user. So a parameter query is required.
If it were me, I would simply use.
The other way to go around is to use a QueryDef.
My head thinks, why do you need to use Query def, a very expensive procedure when you can sort it out by simple Execute? So I would like to know what method would you prefer. The pros and cons maybe.
Just a quick question. Let us say you have an action Query as simple as inserting a record with just two fields Name and Date into a table. Just to make it a bit complicated, let us say it needs to be dynamic or in other words need to take the current date and the current user. So a parameter query is required.
If it were me, I would simply use.
Code:
CurrentDB.Execute "INSERT INTO Log " & _
"(UserName, DateAccessed) VALUES " & _
"('" & GetLogonName & "', " & Format(Today, "\#mm\/dd\/yyyy\#") & ");"
Code:
Dim query As QueryDef
Set query = dbs.CreateQueryDef("", "INSERT INTO LOG (UserName,DateAccessed)" & _
" VALUES(@user,@time)")
query.Parameters("@user").Value = "Moo"
query.Parameters("@time").Value = Now
query.Execute