View Full Version : a little problem


deepbreath
07-12-2001, 08:56 AM
i need adding a click event on my search form, which displays a list of names. if i click on any name it will open the main form of that particular names, and also diables certain buttons on the main form. these buttons should be enabled when i go to main form directly but only disabled when i come to it through search form.

Angello Pimental
07-12-2001, 09:41 AM
The following code will open up your main form to the record you click on the search form, and disable certain buttons.

Private Sub searchresults_Click()
On Error GoTo Err_searchresults_Click

Dim frmMyForm As Form
Dim ctlMyCtls As Control
Set frmMyForm = Forms!MainForm

Dim stDocName As String
Dim rst As Recordset, strCriteria As String
stDocName = "MainForm"
strCriteria = "[criteria]=" & "'" & Me![searchresults] & "'"
DoCmd.OpenForm stDocName

Set rst = Forms!MainForm.RecordsetClone
rst.FindFirst strCriteria
Forms!MainForm.Bookmark = rst.Bookmark
Me!searchresults = ""

For Each ctlMyCtls In frmMyForm.Controls
If ctlMyCtls.Tag = "disable" Then
ctlMyCtls.Visible = True
ctlMyCtls.Enabled = False
ctlMyCtls.Locked = True

Exit_searchresults_Click:
Exit Sub

Err_searchresults_Click:
MsgBox Err.Description
Resume Exit_searchresults_Click
End Sub

searchresults = name of txt box where results are displayed in
Mainform = name of your Mainform
criteria = criteria by which you have done your search/navigate records

For all the buttons you wish to disable, put disable in the tag property

Give it a go, and report any problems you have
HTH

Angelo



[This message has been edited by Angello Pimental (edited 07-12-2001).]

deepbreath
07-13-2001, 03:42 AM
my search is based on a query, should i use the name of query in criteria or something else, plz explain

Angello Pimental
07-13-2001, 07:07 AM
Ok, I am assuming that you have a form which displays the search information. And that the form is based on a query.
Then the criteria will be field name by which your query did the search.
e.g. If your user searches for peoples names
then [names] would be the criteria

HTH

Angelo

deepbreath
07-14-2001, 04:24 AM
thanks, with few modifications, it works perfectly fine.