Rocky Smolin - Beach Access Software
bchacc at san.rr.com
Thu Jun 8 09:53:34 CDT 2006
Jim: That's going to be a really handy piece of code. Would there be a downside, however, to using On Error Resume Next (Delete Object) On Error GoTo 0 I've done that before but it seem s bit like working without a net. Rocky Hale, Jim wrote: > Rocky, This function has been in my toolkit so long I forget where I got it. > Probably from this list! > Jim Hale > > Function ahtDoesObjExist(strObj As String, intType As Integer) As Boolean > 'This function returns True if an object exists, false if it doesn't > '------------------------------------------------------------------- > Dim strName As String > Dim db As Database > Dim strCon As String > > > On Error GoTo ahtDoesObjExist_Err > > Set db = CurrentDb() > Select Case intType > Case acTable > strName = db.TableDefs(strObj).Name > Case acQuery > strName = db.QueryDefs(strObj).Name > Case acForm, acReport, acMacro, acModule > Select Case intType > Case acForm > strCon = "Forms" > Case acReport > strCon = "Reports" > Case acMacro > strCon = "Scripts" > Case acModule > strCon = "Modules" > End Select > strName = db.Containers(strCon).Documents(strObj).Name > End Select > ahtDoesObjExist = True > > ahtDoesObjExist_Exit: > Exit Function > > ahtDoesObjExist_Err: > ahtDoesObjExist = False > Resume ahtDoesObjExist_Exit > > End Function > > > -----Original Message----- > From: Rocky Smolin - Beach Access Software [mailto:bchacc at san.rr.com] > Sent: Wednesday, June 07, 2006 5:47 PM > To: Access Developers discussion and problem solving > Subject: Re: [AccessD] Modifying a query > > > Jim: > > I think you're right. Delete and re-create was where I was heading if I > want to keep this query in the string of queries the user wants to > execute through a macro that they set up. > > "ahtDoesObjExist " whuzzat? > > > Regards, > > Rocky > > > Hale, Jim wrote: > >> I may have missed this suggestion from earlier in the thread, but why not >> delete the old query and recreate it with the new criteria? I do it a lot >> with passthrough queries but it can be done with regular Access queries as >> well. Something like these code snippets (this ex creates a passthrough >> query) >> >> Dim qdfPassthrough As QueryDef, rstPassthrough As Recordset >> 'delete old version of query >> if ahtDoesObjExist("qryDownload", acQuery) Then DoCmd.DeleteObject >> acQuery, "qryDownload" >> strPassthrough = "SELECT * from GLTLIB.GLMSL" >> ' Create pass-through query >> Set qdfPassthrough = db.CreateQueryDef("qryDownload") >> qdfPassthrough.Connect = "ODBC;DSN=AS400Prod;" >> qdfPassthrough.SQL = strPassthrough >> ' Tell Access to wait as long as the query takes >> qdfPassthrough.ODBCTimeout = 0 >> Set rstPassthrough = qdfPassthrough.OpenRecordset() >> qdfPassthrough.ReturnsRecords = True >> >> query qryDownload will show up in the Database container >> >> Jim Hale >> >> > > *********************************************************************** > The information transmitted is intended solely for the individual or > entity to which it is addressed and may contain confidential and/or > privileged material. Any review, retransmission, dissemination or > other use of or taking action in reliance upon this information by > persons or entities other than the intended recipient is prohibited. > If you have received this email in error please contact the sender and > delete the material from any computer. As a recipient of this email, > you are responsible for screening its contents and the contents of any > attachments for the presence of viruses. No liability is accepted for > any damages caused by any virus transmitted by this email. > -- Rocky Smolin Beach Access Software 858-259-4334 www.e-z-mrp.com