consultancy chorley ASP.NET Server Side Scripting Wigan
Website Development Radcliffe

A Coder's Notes

Email :
bespoke invoice systems Standish Information Technology Advice Worsley
    development systems Ramsbottom
data manipulation Farnworth access databases Whitefield SQL connections Atherton
online accessible software Leyland software compatible Coppull

Get connected and Online Tottington
remote management Makerfield code and design Aspull

Access 2003 Open A Form On A Specific Record - 20/06/2012

In the code behind for the button that's going to open the form...

DoCmd.OpenForm "formname", acNormal, , "[TableID]=" & Me![TableID], , acWindowNormal, Me![ShowID]

The OpenArgs bit is the bit at the end of the openform comand.  OpenArgs is kind of like passing a variable in a URL using the "?ID=" syntax.  What is actually passed is literally the string after the final comma.

"[TableID]=" & Me![TableID] is the form filter.  The form will show all the records matching the query.  In this case on our form there is a field "TableID" and when the sub form opens all the available records have the same "TableID" as the parent form's "TableID"

Me![ShowID] is the OpenArgs bit.  All I'm wating to pass here is a string, value, number whatnot to the next page to act upon.  In this instance I'm also going to include "ShowID" from the parent form.

We click the button.  The few form opens and lists all the available records that match "TableID" to that of the parent form.  Super smashing great marvellous.  BUT...but we want the form not to simply start with whatever the database deems as the first record, we want it to show the particular record WE want to see, in this case the data from the parent form "ShowID" form load in the code behind sorta stuff we use...

Private Sub Form_Load()
   If Not IsNull(Me.OpenArgs) Then
     Dim rs As Object
     Set rs = Me.Recordset.Clone
     rs.FindFirst "[ShowID] = " & Me.OpenArgs
     If Not rs.EOF Then Me.Bookmark = rs.Bookmark
  end if
End Sub

Not EXACTLY sure what's going on here but the main player is rs.FindFirst "[ShowID] = " & Me.OpenArgs .  I think it loops through all the records until it finds one where "ShowID" is the same as the value we passed from the parent form.

That'll do...


Post A Comment

Name Comment
programming services specialist
Valid XHTML 1.0 Transitional