really, i've tried to search this one...
I am trying to open a form2 based on the input from the user on form1. (Literally, the user inputs an upper and lower range to search for tool diameters that meet this criteria - i.e., show all tools between .25 and .3). I can get this all to work using a static query and setting the record source of the form2 to this query. But I'm wondering if doing it in VBA would be better/quicker/smarter/whathaveyou. I have a nasty looking SQL statement that is replacing the query in the code below, i'm pretty sure no syntax errors. When I run the code, I get error that MS doesn't recognize the form in the line Set Forms!frm_DiameterSearchResults.Recordset = sql. So I tried to move this line after the Open statement... but this gives the error that an Application or object is not defined.
any help with the code or with whether i should use this route would be mucho appreciated, gracias
I am trying to open a form2 based on the input from the user on form1. (Literally, the user inputs an upper and lower range to search for tool diameters that meet this criteria - i.e., show all tools between .25 and .3). I can get this all to work using a static query and setting the record source of the form2 to this query. But I'm wondering if doing it in VBA would be better/quicker/smarter/whathaveyou. I have a nasty looking SQL statement that is replacing the query in the code below, i'm pretty sure no syntax errors. When I run the code, I get error that MS doesn't recognize the form in the line Set Forms!frm_DiameterSearchResults.Recordset = sql. So I tried to move this line after the Open statement... but this gives the error that an Application or object is not defined.
any help with the code or with whether i should use this route would be mucho appreciated, gracias
Code:
Private Sub Command13_Click()
On Error GoTo Err_Command13_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim sql As String
sql = "SELECT tbl_CToolInfo.Tool, tbl_CToolInfo.CuttingDiameterNominal, tbl_CToolInfo.TabOn, tbl_TabOnAndName.ToolDescription "
sql = sql & "FROM tbl_CToolInfo INNER JOIN tbl_TabOnAndName ON tbl_CToolInfo.TabOn = tbl_TabOnAndName.TabOn "
sql = sql & "WHERE tbl_CToolInfo.CuttingDiameterNominal Between '" & [Forms]![frm_SearchExistTool]![Text8] & "' And '" & [Forms]![frm_SearchExistTool]![Text10] & "' "
sql = sql & "AND tbl_TabOnAndName.ToolDescription Like '" & " * " & [Forms]![frm_SearchExistTool]![Text15] & " * " & "'"
sql = sql & "ORDER BY tbl_CToolInfo.CuttingDiameterNominal;"
Set Forms!frm_DiameterSearchResults.Recordset = sql
stDocName = "frm_DiameterSearchResults"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, "frm_SearchExistTool"
Exit_Command13_Click:
Exit Sub
Err_Command13_Click:
MsgBox Err.Description
Resume Exit_Command13_Click
End Sub