?
Solved

Custom Save Query function not working in Access2002.

Posted on 2003-03-24
6
Medium Priority
?
304 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:Mavreich
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 8195034
I think the wzmain for Access 2002 is called ACWZMAIN.MDE, and should be in the Office10 folder in your Office installation directory.
0
 
LVL 2

Author Comment

by:Mavreich
ID: 8195278
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
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 1000 total points
ID: 8195335
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:Mavreich
ID: 8199057
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 8199167
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
 
LVL 2

Author Comment

by:Mavreich
ID: 8199246
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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Suggested Courses

752 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