Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Dynamically name a query with Users ID

Avatar of Sandra Smith
Sandra SmithFlag for United States of America asked on
Microsoft AccessMicrosoft Development
7 Comments1 Solution364 ViewsLast Modified:
I havse an ACCESS 2003 database that could have users trying to save data at the same time.  There is a process that check records and without getting into a lot of detail, I would like to create a querydef with the query name created dynamicall with the user's ID at the end so if more than one user is running threprocess, they don't crash into each other trying to use the same query.  I don't even know if that is posisible, but I am attaching my starting point.
Public Sub AppendSPOT(strUserId As String, dteActivityDate As Date)
Dim strDelete As String, strAppendSPOT As String, strUserId As String
Dim strNoSpotData As String, qdfNoSpotData As QueryDef
Set db = CurrentDb
'Selects data from the production database to see if any spot data
'already exists.  If it has all been deleted, either by user or system,
'then there should be no data in the EmpStats table either.  The row count
'returned for this query satisfies this criteria of rows existing or not
strNoSpotData = "SELECT tblProductionData.UserID, tblProductionData.SystemUserID, " & _
    "tblProductionData.ActivityDate, tblProductionData.WFLWID, tblWorkFlows.DSRID " & _
    "FROM tblProductionData INNER JOIN tblWorkFlows ON " & _
    "tblProductionData.WFLWID = tblWorkFlows.WFLWID " & _
    "WHERE tblProductionData.UserID = '" & strUserId & "' AND " & _
    "tblProductionData.ActivityDate = #" & dteActivityDate & "# AND " & _
    "tblWorkFlows.DSRID = 'DSR3' "
Set qdfNoSpotData = db.CreateQueryDef("qryNoSpotData & strUser & ", strNoSpotData)
Set rs = CurrentDb.OpenRecordset("qryNoSpotData & strUser & ")
If rs.RecordCount > 0 Then
    DoCmd.RunSQL strDelete  'For this example, deleted
    DoCmd.RunSQL strAppendSPOT  'For this example, deleted
    DoCmd.RunSQL strDelete  'For this example, deleted
End If
    DoCmd.DeleteObject acQuery, ("qryNoSpotData & strUser & ")
Set rs = Nothing
Set qdfNoSpotData = Nothing
Set db = Nothing
End Sub