I have a database that was created by a SQL programmer, and it's all wonderful, except that the programmer never completed it, and it's pretty sophisticated for my user community, so that means no one can complete it or maintain it.
I'm re-writing its functionality (and completing it!) so that it just uses familiar Access utilities. It doesn't need anything fancy, so although it's taking me a little time to accomplish, it's going to be simpler for the users to maintain, to the extent that they are able.
Currently, there is a form that presents one unbound control that functions as a filter for a specific field, and three pairs of controls, each pair of which allows the user to select a field and a sort order for that field. (I've attached a picture of the form.)
The underlying code simply runs a query and presents the data table, but I want to present the data in a sensibly-designed form instead of just in an unwieldly line of fields marching off to the right. Here's the code, and how do I make the code use the form I've created instead of just the raw query:
** Edit **
[imgnothumb]http://bytes.com/attachments/attachment/5332d1313617944/billhold-form.jpg[/imgnothumb]
I'm re-writing its functionality (and completing it!) so that it just uses familiar Access utilities. It doesn't need anything fancy, so although it's taking me a little time to accomplish, it's going to be simpler for the users to maintain, to the extent that they are able.
Currently, there is a form that presents one unbound control that functions as a filter for a specific field, and three pairs of controls, each pair of which allows the user to select a field and a sort order for that field. (I've attached a picture of the form.)
The underlying code simply runs a query and presents the data table, but I want to present the data in a sensibly-designed form instead of just in an unwieldly line of fields marching off to the right. Here's the code, and how do I make the code use the form I've created instead of just the raw query:
Code:
'Open the selected query. Replace the order by clause with the order selected by user.
Private Sub cmdViewCategoryData_Click()
Dim DB
Dim qd As DAO.QueryDef
'Dim rs As Recordset
Dim Sort As String
Dim sql As String
Dim queryName As String
Dim querySql As String
Dim OrderByPosition As Integer
Sort = " ORDER BY [" & Me.cboSort1.Value & "] " & Me.FirstSortAscDesc.Value & ", [" & Me.cboSort2.Value & "] " & Me.SecondSortAscDesc.Value & ", [" & Me.cboSort3.Value & "] " & Me.ThirdSortAscDesc.Value
'Sort = " ORDER BY [" & Me.cboSort1.Value & "], [" & Me.cboSort2.Value & "], [" & Me.cboSort3.Value & "]"
queryName = "qry" & Me.cboHospCat.Value
Set DB = CurrentDb()
Set qd = DB.QueryDefs(queryName)
querySql = qd.sql
'If there is an Order By clause, replace it with new order by, or else add it to end:
If InStr(querySql, "ORDER BY") > 0 Then
OrderByPosition = InStr(querySql, "ORDER BY")
Else
OrderByPosition = InStr(querySql, ";") 'Len(querySql)
End If
querySql = Left(querySql, OrderByPosition - 1)
querySql = querySql & Sort & ";"
qd.sql = querySql
DoCmd.OpenQuery queryName
Set qd = Nothing
Set DB = Nothing
End Sub
[imgnothumb]http://bytes.com/attachments/attachment/5332d1313617944/billhold-form.jpg[/imgnothumb]
Comment