Custom Save Query function not working in Access2002.

Hi all,

I have a Access97 database that has a custom for for creating queries.  On the form is a button for activating the code.  The code is posted below.

It references the wzmain80.wlib_stUniquedocname.  

My problem is this.  I have migrated the application to Access2002.  This particular code no longer works.  I have tried adding the file wzmain80 into the references,  but as it is an assess97 mde file Access2002 won't reference it.

The users run the front end as a MDE as well.  How to I get this to work in Access2002.

Thanking you all in advance and greatfully appreciating all help.

Regards
Mavreich

Private Sub cmdCreateQDF_Click()
On Error GoTo Error_cmdCreateQDF
Dim db As Database
Dim qdf As QueryDef
Dim strName As String
   'first get a unique name for the querydef object
   strName = Application.Run("wzmain80.wlib_stUniquedocname", "Query1", acQuery)
   strName = InputBox("Please specify a query name", "Save As", strName)
   If Not strName = vbNullString Then
      'only create the querydef if user really wants to.
      Set db = CurrentDb
      Set qdf = db.CreateQueryDef(strName, Me.txtSQL)
      qdf.Close
   Else
      'ok, so they don't want to
      'MsgBox "The save operation was cancelled." & vbCrLf & _
      '   "Please try again.", vbExclamation + vbOKOnly, "Cancelled"
   End If
   Me.lbxListSQL.Requery
Exit_cmdCreateQDF:
   On Error Resume Next
   qdf.Close
   Set qdf = Nothing
   db.QueryDefs.Refresh
   Set db = Nothing
   Exit Sub
Error_cmdCreateQDF:
   Resume Exit_cmdCreateQDF
End Sub
LVL 2
MavreichAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

shanesuebsahakarnCommented:
I think the wzmain for Access 2002 is called ACWZMAIN.MDE, and should be in the Office10 folder in your Office installation directory.
0
MavreichAuthor Commented:
Hi, shanesuebsahakarn

Thankyou for that pointer.  It was spot on.  However the only glitch is am having is that it will not select a unique save name for the query.

When the user saves the query it pops up a input window with a default save name.

Example:  Default safe name is Query1.  If there is a query already saved with the name then the next default save name should be Query2.

In this case it always comes up with Query1.

Below is the modified code.

Again i look forward to your responses.

Regards
Mavreich

Private Sub cmdCreateQDF_Click()
On Error GoTo Error_cmdCreateQDF
Dim db As Database
Dim qdf As QueryDef
Dim strName As String
   'first get a unique name for the querydef object
    strName = acwzmain.wlib_StUniqueDocName("Query1", acQuery)
     
   strName = InputBox("Please specify a query name", "Save As", strName)
   If Not strName = vbNullString Then
      'only create the querydef if user really wants to.
      Set db = CurrentDb
      Set qdf = db.CreateQueryDef(strName, Me.txtSQL)
      qdf.Close
   Else
      'ok, so they don't want to
      'MsgBox "The save operation was cancelled." & vbCrLf & _
      '   "Please try again.", vbExclamation + vbOKOnly, "Cancelled"
   End If
   Me.lbxListSQL.Requery
Exit_cmdCreateQDF:
   On Error Resume Next
   qdf.Close
   Set qdf = Nothing
   db.QueryDefs.Refresh
   Set db = Nothing
   Exit Sub
Error_cmdCreateQDF:
   Resume Exit_cmdCreateQDF
End Sub
0
shanesuebsahakarnCommented:
I haven't used this particular function before so I can't tell you what the problem is, but you could use this to get a default save name:
Dim lngMax As Long

lngMax=0
For Each qdf In CurrentDb.QueryDefs
   If Left$(qdf.Name,5)="Query" Then
      If Val(Right$(qdf.Name,6)) > lngMax Then lngMax = Val(Right$(qdf.Name,6))
   End If
Next
strName = "Query" & (lngMax+1)

Use this code in place of the StUniqueDocName line - I think it will do it for you.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

MavreichAuthor Commented:
Hi shanesuebsahakarn,


Your code keeps coming up with query1 as well.  it does not increment.

Thanks for the help though.  It is appreciated.

Regards
Mavreich
0
shanesuebsahakarnCommented:
Doh! The line:
If Val(Right$(qdf.Name,6)) > lngMax Then lngMax = Val(Right$(qdf.Name,6))

should read:
If Val(Mid$(qdf.Name,6)) > lngMax Then lngMax = Val(Mid$(qdf.Name,6))

Sorry about that!
0
MavreichAuthor Commented:
Hi shanesuebsahakarn,

Perfect.   I would like to thankyou for your speedy responses and great help.

As always Experts Exchange live up to it name.

With much apreciation
Mavreich
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

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.