G
Guest
I have a database that has about 10 tables that are exactly alike but they
are not related in any way. I found code that allows the user to open a form
and do a search on anything in the form, sort by column, add records, delete
records, etc. The problem is that there are modules where the table to use
is hardcoded. I'd like to create one form and pass code to the module that
will tell it which table to use. My main form has buttons that they will
click based on product. I really don't want to create a form for every table
that will have exactly the same fields in it but with different data. Since
I will know which table should be opened when they click the button on the
main form, I would think I could pass that information. I can get the form
name but when I try to pass it, the sort does not work. Here's tpart of the
code from the module:
Public Function BuildFilteredSQL(filtertext As String, filterType As String,
sqltext As String) As String
On Error GoTo Err_BuildFilteredSQL
'Builds a sql statement using the filtertext, filtertype and sqltext
'The filtertext is the string to filter on
'The filterType determines what fields are used to do the filtering on
'Note: these are hardcoded in this routine
'the sqltext determines the base sql query to modify
Dim sql As String
Dim fff As Integer
Dim sqlwhere As String
Dim doneFlag As Integer
sql = sqltext
'good for debugging
'MsgBox sql & "||"
'take off extra spaces and ";" if they exist
sql = RTrim(sql)
If (Right(sql, 1) = ";") Then
sql = Left(sql, Len(sql) - 1)
End If
'Build a new WHERE clause based on passed in parameters
If (filtertext <> "") And (filterType <> "") Then
' Select Case filterType
' Case "Customer"
' sqlwhere = "WHERE ((tblCustomer.FirstName Like '*" &
filtertext & "*') OR (tblCustomer.LastName Like '*" & filtertext & "*') OR
(tblCustomer.CompanyName Like '*" & filtertext & "*') OR (tblCustomer.Address
Like '*" & filtertext & "*') OR (tblCustomer.Phone Like '*" & filtertext &
"*') OR (tblCustomer.Mobile Like '*" & filtertext & "*') OR
(tblCustomer.Email Like '*" & filtertext & "*'))"
filterType = "WHERE ((ASHRAEHousings.SerialNumber Like '*" &
filtertext & "*') OR (ASHRAEHousings.Product Like '*" & filtertext & "*') OR
(ASHRAEHousings.ControlNumber Like '*" & filtertext & "*') OR
(ASHRAEHousings.SoldTo Like '*" & filtertext & "*') OR
(ASHRAEHousings.EndUser Like '*" & filtertext & "*') OR
(ASHRAEHousings.SOSelling Like '*" & filtertext & "*') OR
(ASHRAEHousings.SOSellingDestination Like '*" & filtertext & "*') OR
(ASHRAEHousings.ProductCode Like '*" & filtertext & "*'))"
' Case "Resource"
' sqlwhere = "WHERE ((tblResource.FirstName Like '*" &
filtertext & "*') OR (tblResource.LastName Like '*" & filtertext & "*') OR
(tblResource.NameOnSchedule Like '*" & filtertext & "*') OR
(tblResource.Phone Like '*" & filtertext & "*') OR (tblResource.MobilePhone
Like '*" & filtertext & "*') OR (tblResource.Email Like '*" & filtertext &
"*'))"
' End Select
End If
In the above code, ASHRAE Housings is just one of the tables. It's the
filterType that will not worik
Thanks to anyone that can help.
are not related in any way. I found code that allows the user to open a form
and do a search on anything in the form, sort by column, add records, delete
records, etc. The problem is that there are modules where the table to use
is hardcoded. I'd like to create one form and pass code to the module that
will tell it which table to use. My main form has buttons that they will
click based on product. I really don't want to create a form for every table
that will have exactly the same fields in it but with different data. Since
I will know which table should be opened when they click the button on the
main form, I would think I could pass that information. I can get the form
name but when I try to pass it, the sort does not work. Here's tpart of the
code from the module:
Public Function BuildFilteredSQL(filtertext As String, filterType As String,
sqltext As String) As String
On Error GoTo Err_BuildFilteredSQL
'Builds a sql statement using the filtertext, filtertype and sqltext
'The filtertext is the string to filter on
'The filterType determines what fields are used to do the filtering on
'Note: these are hardcoded in this routine
'the sqltext determines the base sql query to modify
Dim sql As String
Dim fff As Integer
Dim sqlwhere As String
Dim doneFlag As Integer
sql = sqltext
'good for debugging
'MsgBox sql & "||"
'take off extra spaces and ";" if they exist
sql = RTrim(sql)
If (Right(sql, 1) = ";") Then
sql = Left(sql, Len(sql) - 1)
End If
'Build a new WHERE clause based on passed in parameters
If (filtertext <> "") And (filterType <> "") Then
' Select Case filterType
' Case "Customer"
' sqlwhere = "WHERE ((tblCustomer.FirstName Like '*" &
filtertext & "*') OR (tblCustomer.LastName Like '*" & filtertext & "*') OR
(tblCustomer.CompanyName Like '*" & filtertext & "*') OR (tblCustomer.Address
Like '*" & filtertext & "*') OR (tblCustomer.Phone Like '*" & filtertext &
"*') OR (tblCustomer.Mobile Like '*" & filtertext & "*') OR
(tblCustomer.Email Like '*" & filtertext & "*'))"
filterType = "WHERE ((ASHRAEHousings.SerialNumber Like '*" &
filtertext & "*') OR (ASHRAEHousings.Product Like '*" & filtertext & "*') OR
(ASHRAEHousings.ControlNumber Like '*" & filtertext & "*') OR
(ASHRAEHousings.SoldTo Like '*" & filtertext & "*') OR
(ASHRAEHousings.EndUser Like '*" & filtertext & "*') OR
(ASHRAEHousings.SOSelling Like '*" & filtertext & "*') OR
(ASHRAEHousings.SOSellingDestination Like '*" & filtertext & "*') OR
(ASHRAEHousings.ProductCode Like '*" & filtertext & "*'))"
' Case "Resource"
' sqlwhere = "WHERE ((tblResource.FirstName Like '*" &
filtertext & "*') OR (tblResource.LastName Like '*" & filtertext & "*') OR
(tblResource.NameOnSchedule Like '*" & filtertext & "*') OR
(tblResource.Phone Like '*" & filtertext & "*') OR (tblResource.MobilePhone
Like '*" & filtertext & "*') OR (tblResource.Email Like '*" & filtertext &
"*'))"
' End Select
End If
In the above code, ASHRAE Housings is just one of the tables. It's the
filterType that will not worik
Thanks to anyone that can help.