OpenForm Question

G

Guest

I have a user update form - frmUpdate and a search form - frmSearch. The
search form runs off a query; the header has searchable fields: CompanyName,
ItemName, Model, SerialNumber. The Details sections includes these fields
and PID which is a Primary key on the Products table. Based on the search
selections I get multiple records (expected). I would like to use the search
list records as a filter to open the 'frmUpdate'. I have created a command
button on the 'frmSearch' header and put in the following code. This opens
'frmUpdate' but only with the first record in the search list. What am I
doing wrong? I have spent the last week playing with this, searching through
many forums, and searching the help sections, but no go. Thanks!

Private Sub cmdOpenUpdate_Click()
On Error GoTo Err_cmdOpenUpdate_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmUpdate"

stLinkCriteria = "[PID]=" & Me![PID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenUpdate_Click:
Exit Sub

Err_cmdOpenUpdate_Click:
MsgBox Err.Description
Resume Exit_cmdOpenUpdate_Click

End Sub
 
G

Guest

Why not place a filter on the form using the [PID] you provide. I assume
there are more [PID's] with the same values because otherwise you should get
one record returned.

So in the On_Open of the form "frmUpdate"

me.filter= "[PID]= " & forms!frmSearch![PID]
me.filteron=true
 
G

Guest

Thanks for your help.

The form "frmUpdate" is also opened without going through the search form.
The issue I have is that some users wish to go directly to the update form
and others want to be able pull up certain records to update.

Lakshmi

Maurice said:
Why not place a filter on the form using the [PID] you provide. I assume
there are more [PID's] with the same values because otherwise you should get
one record returned.

So in the On_Open of the form "frmUpdate"

me.filter= "[PID]= " & forms!frmSearch![PID]
me.filteron=true

--
Maurice Ausum


LBN said:
I have a user update form - frmUpdate and a search form - frmSearch. The
search form runs off a query; the header has searchable fields: CompanyName,
ItemName, Model, SerialNumber. The Details sections includes these fields
and PID which is a Primary key on the Products table. Based on the search
selections I get multiple records (expected). I would like to use the search
list records as a filter to open the 'frmUpdate'. I have created a command
button on the 'frmSearch' header and put in the following code. This opens
'frmUpdate' but only with the first record in the search list. What am I
doing wrong? I have spent the last week playing with this, searching through
many forums, and searching the help sections, but no go. Thanks!

Private Sub cmdOpenUpdate_Click()
On Error GoTo Err_cmdOpenUpdate_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmUpdate"

stLinkCriteria = "[PID]=" & Me![PID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenUpdate_Click:
Exit Sub

Err_cmdOpenUpdate_Click:
MsgBox Err.Description
Resume Exit_cmdOpenUpdate_Click

End Sub
 
G

Guest

Maurice:

Thanks for your help. I was able to do what I need with the following code
(thanks to help on another forum). Appreciate your taking the time to help.

' If I'm filtered
If Me.FilterOn And (Me.Filter <> "") Then
' Open using my filter
DoCmd.OpenForm stDocName, WhereCondition:=Me.Filter
End If
 
G

Guest

Thanks for posting your solution, appreciated.
--
Maurice Ausum


LBN said:
Maurice:

Thanks for your help. I was able to do what I need with the following code
(thanks to help on another forum). Appreciate your taking the time to help.

' If I'm filtered
If Me.FilterOn And (Me.Filter <> "") Then
' Open using my filter
DoCmd.OpenForm stDocName, WhereCondition:=Me.Filter
End If

LBN said:
I have a user update form - frmUpdate and a search form - frmSearch. The
search form runs off a query; the header has searchable fields: CompanyName,
ItemName, Model, SerialNumber. The Details sections includes these fields
and PID which is a Primary key on the Products table. Based on the search
selections I get multiple records (expected). I would like to use the search
list records as a filter to open the 'frmUpdate'. I have created a command
button on the 'frmSearch' header and put in the following code. This opens
'frmUpdate' but only with the first record in the search list. What am I
doing wrong? I have spent the last week playing with this, searching through
many forums, and searching the help sections, but no go. Thanks!

Private Sub cmdOpenUpdate_Click()
On Error GoTo Err_cmdOpenUpdate_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmUpdate"

stLinkCriteria = "[PID]=" & Me![PID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenUpdate_Click:
Exit Sub

Err_cmdOpenUpdate_Click:
MsgBox Err.Description
Resume Exit_cmdOpenUpdate_Click

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top