DoCmd.RunSQL in Access 2007

Posted on 2009-12-18
Medium Priority
Last Modified: 2013-11-28
I have an Access 2007 DB that we are using as a project management/ticket tracking solution.  My boss wants to be able to track how long different groups work on the project so we can start to trend and see where the bottlenecks are.  

So, I have the main table called Issues, and a 2nd table called tblWithGroup.  The structure for tblWithGroup is:

ID (PK),
Issues_ID (FK to Issues table),
Group (linked to Issues table field called with_group),

The fields in Issues that come in to play are:

with_group (list box with list of groups)
group_ID links to tblWithGroup ID so we can match records
ID (pk)
Step 1 should be, look and see if there is already an entry in Issues.group_ID
If not, add a new record to tblWithGroup and update group_ID
If group_ID = tblWithGroup.ID put an end_date THEN add a new record to tblWithGroup and update group_ID

Right now I am trying to do it with docmd.runsql (    DoCmd.RunSQL "UPDATE tblWithGroup SET End_Date = Date() WHERE me!group_ID = tblWithgroup.ID;"), but it doesn't accespt the VB of me!group_ID, and if I put it in, it says you are about to update 1 record.  (got the code attached so you can see the whole thing)

How can I do a WHERE clause in VBA so that it will match group_id to tblwithGroup.ID and update the record?

I'm brand new to access and programming in general, so I am hoping I'm making sense!
Question by:COSMTARFCU
  • 3
  • 2

Author Comment

ID: 26079963
apparently I forgot to add the code, so here it is...sorry!
Private Sub with_group_AfterUpdate()


Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("tblWithGroup")

With rs

If Me!group_ID = Null Then
    Me!group_ID = Null
    DoCmd.RunSQL "UPDATE tblWithGroup SET End_Date = Date() WHERE me!group_ID = tblWithgroup.ID;"
End If

    !Issue_ID = Me.ID
    !Group = Me.with_group
    !Start_Date = Date
    Me!group_ID = ID
End With

If Not rs Is Nothing Then
    Set rs = Nothing
End If

Exit Sub

End Sub

Open in new window

LVL 13

Expert Comment

ID: 26080897

Concatenate me!group_ID before executing the command.

dim s as string
s = "UPDATE tblWithGroup SET End_Date = Date() WHERE tblWithgroup.ID= " + me!group_ID  + ";"
DoCmd.RunSQL s

Open in new window


Author Comment

ID: 26081799
Thanks.  When I tried that, it still asks me to enter parameter value Me!group_ID?
Is there a different way to do a Where clause in vba instead of doing the docmd.runsql?
Thanks for the help!

Author Comment

ID: 26081836
Actually, saw a typo in my code...but I do get a type mismatch. error now.
tblWithGroup.ID is an autonumber, and issues.group_ID is a Number.  Any way around that?
LVL 13

Accepted Solution

sameer2010 earned 2000 total points
ID: 26089331
if group_id is a number, fir convert it to string for concatenation.
dim s as string
s = "UPDATE tblWithGroup SET End_Date = Date() WHERE tblWithgroup.ID= " + Str(me!group_ID)  + ";"
DoCmd.RunSQL s

Open in new window


Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question