Search and open form (1 Viewer)

xyba

Registered User.
Local time
Today, 12:13
Joined
Jan 28, 2016
Messages
189
Hi

In a nav form's default subform I want to add a search facility (text box and button). In the button OnClick event I want another subform to open with the searched record.

I have the below code for my search button but I don't know what to add to get it to open the result in another subform.

Code:
Private Sub btnSrch_Click()
If IsNull(SearchBox) = False Then
Me.Recordset.FindFirst "[OldID]=" & SearchBox
    Me!SearchBox = Null
        If Me.Recordset.NoMatch Then
            MsgBox "No Record Found", vbOKOnly + vbInformation, "Sorry"
                Me!SearchBox = Null
        End If
End If
End Sub
 

isladogs

MVP / VIP
Local time
Today, 12:13
Joined
Jan 14, 2017
Messages
18,209
Last edited:

xyba

Registered User.
Local time
Today, 12:13
Joined
Jan 28, 2016
Messages
189
There are many examples of this functionality on the forum and elsewhere.
For example taken from Similar Threads list https://www.access-programmers.co.uk/forums/showthread.php?t=288151
Also http://allenbrowne.com/ser-62.htm

EDIT
Did you see my answer to the graph label format thread posted 2 days ago?
https://www.access-programmers.co.uk/forums/showpost.php?p=1637692&postcount=12

Thanks for the reply. The first link shows how to open the result in another form. I want to open another subform within the navigation form not outside of it. If I used the code mentioned in that thread wouldn't it open a separate form outside the navigation form?

The second link gives a 404 error.

Sorry, no I hadn't seen your reply in the other thread. I have managed to change all other properties apart from the data values. But, as you said, it looks like it's not possible to change that in Access. Thanks for the reply on that one.
 

isladogs

MVP / VIP
Local time
Today, 12:13
Joined
Jan 14, 2017
Messages
18,209
I don't use navigation forms which don't work like 'normal' forms.
I've fixed the second link to Allen Browne's website
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:13
Joined
May 7, 2009
Messages
19,233
do you have another subform (another navigation button) in the navigation?
if you have you can show the form there:

me.navigationbuttonXX.NavigationTargetName = 'Form.theformToOpen"

but you cannot perform any filtering through vba on the newsubform.
you must do it on the underlying query of the form that you open.
 

xyba

Registered User.
Local time
Today, 12:13
Joined
Jan 28, 2016
Messages
189
I don't use navigation forms which don't work like 'normal' forms.

Maybe I've not explained very well what I'm looking to achieve.

As an example, a navform has 2 subforms named Search and Result. In subform Search I want to enter the search value in a text box and, if the record exists, when the button is clicked the user is taken to subform Result, showing the record(s). Is this not normal?

I would assume that the method in the link would open the main form Result as a separate window and not simply go to the subform Result staying within the navform.

It's likely I'm incorrect in my assumption?
 

isladogs

MVP / VIP
Local time
Today, 12:13
Joined
Jan 14, 2017
Messages
18,209
Just to repeat I don't use the Access navigation form as I find them difficult to modify.

However IIRC, trying to use more than one subform in a navigation form doesn't work well. You may need to use a standard form with 2 subforms instead.
 

xyba

Registered User.
Local time
Today, 12:13
Joined
Jan 28, 2016
Messages
189
Just to repeat I don't use the Access navigation form as I find them difficult to modify.

However IIRC, trying to use more than one subform in a navigation form doesn't work well. You may need to use a standard form with 2 subforms instead.

Ah, okay, thanks Colin.
 

xyba

Registered User.
Local time
Today, 12:13
Joined
Jan 28, 2016
Messages
189
do you have another subform (another navigation button) in the navigation?
if you have you can show the form there:

me.navigationbuttonXX.NavigationTargetName = 'Form.theformToOpen"

but you cannot perform any filtering through vba on the newsubform.
you must do it on the underlying query of the form that you open.

Yes, I have another subform. I'll give this a go, thank you but, does that code go in the OnClick event?

I have subform Search and subform Result so how would that affect the code?
 

Users who are viewing this thread

Top Bottom