Open form to specific record from button on continuous form

  • Follow


I have a continous form with limited data and I would like to have a button 
which then opens up a selected record in another form. I've placed the button 
via the wizard and, while it opens the form, it doesn't open to the selected 
record.

It it possible to have a button on a continous form which  would then open 
to a bookmarked record on another form?  The wizard put this code, is it 
possible to modify this?

Thanks.

Private Sub btnOpenForm_Click()
On Error GoTo btnOpenForm_Click_Err

    DoCmd.OpenForm "frmName", acNormal, "", """[id]="" & [id]", , acNormal


btnOpenForm_Click_Exit:
    Exit Sub

btnOpenForm_Click_Err:
    MsgBox Error$
    Resume btnOpenForm_Click_Exit

End Sub
0
Reply Utf 12/22/2009 7:28:06 PM

Private Sub btnOpenForm_Click()
On Error GoTo btnOpenForm_Click_Err
    Dim strWhere As String

    'for a number type [ID]
    strWhere = "[ID] = " & Me.[ID]

    'for a text type [ID]
    strWhere = "[ID] = """ & Me.[ID] & """"

    DoCmd.OpenForm "frmName", , , strWhere


btnOpenForm_Click_Exit:
    Exit Sub

btnOpenForm_Click_Err:
    MsgBox Error$
    Resume btnOpenForm_Click_Exit

End Sub

Note: replace [ID] with the name of the field that you are using to find the 
matching record on the second form.



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia

"sml" <sml@discussions.microsoft.com> wrote in message 
news:BAE00FD3-6CC6-42A3-93F1-753376670C56@microsoft.com...
>I have a continous form with limited data and I would like to have a button
> which then opens up a selected record in another form. I've placed the 
> button
> via the wizard and, while it opens the form, it doesn't open to the 
> selected
> record.
>
> It it possible to have a button on a continous form which  would then open
> to a bookmarked record on another form?  The wizard put this code, is it
> possible to modify this?
>
> Thanks.
>
> Private Sub btnOpenForm_Click()
> On Error GoTo btnOpenForm_Click_Err
>
>    DoCmd.OpenForm "frmName", acNormal, "", """[id]="" & [id]", , acNormal
>
>
> btnOpenForm_Click_Exit:
>    Exit Sub
>
> btnOpenForm_Click_Err:
>    MsgBox Error$
>    Resume btnOpenForm_Click_Exit
>
> End Sub 


0
Reply Jeanette 12/22/2009 7:57:00 PM

That doesn't look like the wizard code I generated in Access 2003 for a text
field.  Assuming [id] is a text field, try something like:

DoCmd.OpenForm "frmName", acNormal, , "[id]= ' " & Me.[id] & " ' "

If there could be an apostrophe in [id]:

DoCmd.OpenForm "frmName", acNormal, , "[id]= " " " & Me.[id] & " " " "

Spaces between the quotes are for clarity.  You do not need the spaces.
Access will probably get rid of them on its own.

If [id] is a number field:

DoCmd.OpenForm "frmName", acNormal, , "[id]= " & Me.[id]

You do not say where the command button is located.  It will need to be on
the form itself, so it appears with every record on the continuous form.  You
would click the button in the record you want to see.



sml wrote:
>I have a continous form with limited data and I would like to have a button 
>which then opens up a selected record in another form. I've placed the button 
>via the wizard and, while it opens the form, it doesn't open to the selected 
>record.
>
>It it possible to have a button on a continous form which  would then open 
>to a bookmarked record on another form?  The wizard put this code, is it 
>possible to modify this?
>
>Thanks.
>
>Private Sub btnOpenForm_Click()
>On Error GoTo btnOpenForm_Click_Err
>
>    DoCmd.OpenForm "frmName", acNormal, "", """[id]="" & [id]", , acNormal
>
>btnOpenForm_Click_Exit:
>    Exit Sub
>
>btnOpenForm_Click_Err:
>    MsgBox Error$
>    Resume btnOpenForm_Click_Exit
>
>End Sub

-- 
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200912/1

0
Reply BruceM 12/22/2009 8:20:26 PM

Worked like a charm. Thanks!

"Jeanette Cunningham" wrote:

> Private Sub btnOpenForm_Click()
> On Error GoTo btnOpenForm_Click_Err
>     Dim strWhere As String
> 
>     'for a number type [ID]
>     strWhere = "[ID] = " & Me.[ID]
> 
>     'for a text type [ID]
>     strWhere = "[ID] = """ & Me.[ID] & """"
> 
>     DoCmd.OpenForm "frmName", , , strWhere
> 
> 
> btnOpenForm_Click_Exit:
>     Exit Sub
> 
> btnOpenForm_Click_Err:
>     MsgBox Error$
>     Resume btnOpenForm_Click_Exit
> 
> End Sub
> 
> Note: replace [ID] with the name of the field that you are using to find the 
> matching record on the second form.
> 
> 
> 
> Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
> 
> "sml" <sml@discussions.microsoft.com> wrote in message 
> news:BAE00FD3-6CC6-42A3-93F1-753376670C56@microsoft.com...
> >I have a continous form with limited data and I would like to have a button
> > which then opens up a selected record in another form. I've placed the 
> > button
> > via the wizard and, while it opens the form, it doesn't open to the 
> > selected
> > record.
> >
> > It it possible to have a button on a continous form which  would then open
> > to a bookmarked record on another form?  The wizard put this code, is it
> > possible to modify this?
> >
> > Thanks.
> >
> > Private Sub btnOpenForm_Click()
> > On Error GoTo btnOpenForm_Click_Err
> >
> >    DoCmd.OpenForm "frmName", acNormal, "", """[id]="" & [id]", , acNormal
> >
> >
> > btnOpenForm_Click_Exit:
> >    Exit Sub
> >
> > btnOpenForm_Click_Err:
> >    MsgBox Error$
> >    Resume btnOpenForm_Click_Exit
> >
> > End Sub 
> 
> 
> .
> 
0
Reply Utf 12/22/2009 8:44:04 PM


i would like to do the same with my button too but i cant seem to make it work. any ideas how im meant to change my code to do this also?

Private Sub Command48_Click()
On Error GoTo Err_Command48_Click
    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "frmMoreInfo"

End Sub
0
Reply mans (6) 1/14/2010 12:31:25 PM

its ok sorted
0
Reply mans (6) 1/14/2010 1:59:39 PM

5 Replies
3285 Views

(page loaded in 0.093 seconds)











4/10/2014 5:15:23 PM


Reply: