Mavreich
asked on
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_stUniquedocn ame.
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_stUni quedocname ", "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
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_stUniquedocn
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.
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,
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
I think the wzmain for Access 2002 is called ACWZMAIN.MDE, and should be in the Office10 folder in your Office installation directory.
ASKER
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_StUniqueDocN ame("Query 1", 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
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_StUniqueDocN
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,
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
Your code keeps coming up with query1 as well. it does not increment.
Thanks for the help though. It is appreciated.
Regards
Mavreich
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!
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!
ASKER
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
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