I'm having a problem with a form that searches records and displays the results in a subform.
It works fine in access 2000 where I made it, but I now need to make it work in access97.
My form has a text box to input search criteria, and three buttons: Search by Company, Search by Risk, and Edit.
The first two do the search and fill a subform called SearchRecordSelect with resulting records.
After that, the edit button takes the number of the currently selected record and uses it to bring up the details of the same record in another form that takes its data from the same query as the search form.
Right now it won't even do the search. I'm guessing that access97 doesn't like either my syntax or I can't reference queries the same way as in 2000.
I'm using the following code in access2000 and it works.
Option Compare Database
Dim SearchBy As String
Public crecord As Long
Private Sub cmdCompany_Click()
On Error GoTo Err_Command2_Click
Dim stDocName As String
stDocName = "QCompany"
Text0.SetFocus
SearchRecordSelect.SourceObject = "Query.QCompany"
SearchRecordSelect.Requery
SearchBy = "company"
Exit_Command2_Click:
Exit Sub
Err_Command2_Click:
MsgBox Err.Description
Resume Exit_Command2_Click
End Sub
Private Sub cmdRisk_Click()
On Error GoTo Err_Command3_Click
Dim stDocName As String
stDocName = "QRisk"
Text0.SetFocus
SearchRecordSelect.SourceObject = "Query.QRisk"
SearchRecordSelect.Requery
SearchBy = "risk"
Exit_Command3_Click:
Exit Sub
Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click
End Sub
Private Sub cmdEdit_Click()
On Error GoTo Err_Command6_Click
crecord = 0
Dim stDocName As String
Dim stLinkCriteria As String
Select Case SearchBy
Case Is = "company"
stDocName = "CRecordSelect"
crecord = Me.SearchRecordSelect.Form.Recordset.AbsolutePosition + 1
Text0.SetFocus
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord acDataForm, "crecordselect", acGoTo, crecord
Case Is = "risk"
stDocName = "RRecordSelect"
crecord = Me.SearchRecordSelect.Form.Recordset.AbsolutePosition + 1
Text0.SetFocus
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord acDataForm, "rrecordselect", acGoTo, crecord
End Select
Exit_Command6_Click:
Exit Sub
Err_Command6_Click:
MsgBox Err.Description
Resume Exit_Command6_Click
End Sub
Access97 says the form query.qcompany is missspelled or doesn't exist. It seems to be looking for a form as the source object of the subform. Is there code I have to put in to get it to display a query in 97?
Thanks for your help,
-Erica
It works fine in access 2000 where I made it, but I now need to make it work in access97.
My form has a text box to input search criteria, and three buttons: Search by Company, Search by Risk, and Edit.
The first two do the search and fill a subform called SearchRecordSelect with resulting records.
After that, the edit button takes the number of the currently selected record and uses it to bring up the details of the same record in another form that takes its data from the same query as the search form.
Right now it won't even do the search. I'm guessing that access97 doesn't like either my syntax or I can't reference queries the same way as in 2000.
I'm using the following code in access2000 and it works.
Option Compare Database
Dim SearchBy As String
Public crecord As Long
Private Sub cmdCompany_Click()
On Error GoTo Err_Command2_Click
Dim stDocName As String
stDocName = "QCompany"
Text0.SetFocus
SearchRecordSelect.SourceObject = "Query.QCompany"
SearchRecordSelect.Requery
SearchBy = "company"
Exit_Command2_Click:
Exit Sub
Err_Command2_Click:
MsgBox Err.Description
Resume Exit_Command2_Click
End Sub
Private Sub cmdRisk_Click()
On Error GoTo Err_Command3_Click
Dim stDocName As String
stDocName = "QRisk"
Text0.SetFocus
SearchRecordSelect.SourceObject = "Query.QRisk"
SearchRecordSelect.Requery
SearchBy = "risk"
Exit_Command3_Click:
Exit Sub
Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click
End Sub
Private Sub cmdEdit_Click()
On Error GoTo Err_Command6_Click
crecord = 0
Dim stDocName As String
Dim stLinkCriteria As String
Select Case SearchBy
Case Is = "company"
stDocName = "CRecordSelect"
crecord = Me.SearchRecordSelect.Form.Recordset.AbsolutePosition + 1
Text0.SetFocus
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord acDataForm, "crecordselect", acGoTo, crecord
Case Is = "risk"
stDocName = "RRecordSelect"
crecord = Me.SearchRecordSelect.Form.Recordset.AbsolutePosition + 1
Text0.SetFocus
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord acDataForm, "rrecordselect", acGoTo, crecord
End Select
Exit_Command6_Click:
Exit Sub
Err_Command6_Click:
MsgBox Err.Description
Resume Exit_Command6_Click
End Sub
Access97 says the form query.qcompany is missspelled or doesn't exist. It seems to be looking for a form as the source object of the subform. Is there code I have to put in to get it to display a query in 97?
Thanks for your help,
-Erica