DoCmd.RunSQL in Access 2007

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),
Start_Date,
End_Date.

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!
COSMTARFCUAsked:
Who is Participating?
 
sameer2010Commented:
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

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

Stop

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

With rs

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

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

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

Exit Sub

End Sub

Open in new window

0
 
sameer2010Commented:
Hi,

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

0
 
COSMTARFCUAuthor Commented:
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!
0
 
COSMTARFCUAuthor Commented:
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?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.