Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / May 2007

Tip: Looking for answers? Try searching our database.

Jump To A Record

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sharkbyte - 21 May 2007 17:43 GMT
I am attempting to jump to a record, on a form open, using criteria supplied
by the previous form.  I found an earlier discussion, on this topic, but was
unsuccessful in making the code work.  Hopefully someone can help me out.

Here is the code I am trying to run:

DoCmd.OpenForm "frmsinglewrlookup"
   
DoCmd.GoToControl [Forms]![frmsinglewrlookup]![WORK_REQUEST_NO]
DoCmd.FindRecord Me.WORK_REQUEST_NO, acEntire, , acSearchAll, , acCurrent,
True

I have tried putting the last 2 lines on the Open event, of the 2nd form,
with no luck.  It kept looking for a control named the same as the value of
[Forms]![frmsinglewrlookup]![WORK_REQUEST_NO].

However, setting it after the DoCMD.FormOpen returns an Error 2046 - "The
Command or Action 'GoToControl' isn't available now."

If I comment the line, I get the same error, for 'FindRecord'.

Any suggestions?  I think it is partly an event timing issue, but I think
there may be a second problem in that it isn't identifying the control, but
rather the value of that control.

Thanks in advance.

Sharkbyte
IT-1957 - 21 May 2007 17:59 GMT
Let me see if I ubderstand, you have a form open and the you open a second
form, you want to show data related to the record of the first form?
If so have you tried a sub form ? you can do that by going in designe mode,
and select the subform option on the tools toolbar. When it promp about the
relashionship select the same field that you wnat to link on both options.
that will create a sub form that shows all the related records on both forms.
Signature

IT1957

> I am attempting to jump to a record, on a form open, using criteria supplied
> by the previous form.  I found an earlier discussion, on this topic, but was
[quoted text clipped - 24 lines]
>
> Sharkbyte
zionsaal@gmail.com - 21 May 2007 18:50 GMT
> Let me see if I ubderstand, you have a form open and the you open a second
> form, you want to show data related to the record of the first form?
[quoted text clipped - 35 lines]
>
> - Show quoted text -

try this

DoCmd.OpenForm "FormName", , , "WORK_REQUEST_NO=" & Me.WORK_REQUEST_NO
Ken Sheridan - 21 May 2007 18:38 GMT
You can filter the second form by means of the WhereCondition argument of the
OpenForm method.  If WORK_REQUEST_NO is a number data type:

   Dim strCriteria as String

   strCriteria = "WORK_REQUEST_NO = " & Me.WORK_REQUEST_NO
   DoCmd.OpenForm "frmsinglewrlookup", WhereCondition:=strCriteria

If its text data type wrap the value in quotes characters:

   strCriteria = "WORK_REQUEST_NO = """ & Me.WORK_REQUEST_NO & """"

Alternatively to navigate to the first matching record in the second form
rather than filtering the form first go to the record in a clone of the
second form's recordset and then synchronize the form's book mark with the
clone's bookmark:

   Dim frm as Form
   Dim rst As Object
   
   DoCmd.OpenForm "frmsinglewrlookup"

   Set frm = Forms("frmsinglewrlookup")
   Set rst = frm.Recordset.Clone
   
   With rst
      .FindFirst "WORK_REQUEST_NO = " & Me.WORK_REQUEST_NO
      If Not .NoMatch Then
           frm.Bookmark = .Bookmark
      Else
           MsgBox "No matching record.", vbInformation, "Warning"
      End If
   End With

Again the above assumes the WORK_REQUEST_NO is a number data type.

Ken Sheridan
Stafford, England

> I am attempting to jump to a record, on a form open, using criteria supplied
> by the previous form.  I found an earlier discussion, on this topic, but was
[quoted text clipped - 24 lines]
>
> Sharkbyte
JK - 22 May 2007 06:54 GMT
Hi, Sharkbyte,

In the second form you are trying to find WORK_REQUEST_NO to find itselef by
going to that record, albeit unsuccessfully, and making it the target of the
find. You better off using OpenArgs .

In the First form:

'++++++++ WORK_REQUEST_NO is *Number* ++

Private Sub  Something
   Dim strForm As String, numToFind As Long

   strForm = "frmsinglewrlookup"
   numToFind = Nz(FieldIntheForm, 0)

   'Open the form
   'numToFind is te open argument in the 2nd form
   DoCmd.OpenForm strForm, acNormal, , , , , numToFind

   'Move the focus to the second form
   DoCmd.SelectObject acForm, strForm

End Sub

In the Second From (Open Event):

Private Sub Form_Open(Cancel As Integer)
   Dim numArg as long

   If IsNull(Me.Form.OpenArgs) Then
       Exit Sub
  Else
       numArg = Me.Form.OpenArgs
       DoCmd.GoToControl "WORK_REQUEST_NO"
       DoCmd.FindRecord numArg
   End If
   DoCmd.GoToControl     whatever
End Sub

'++++++++ WORK_REQUEST_NO is *String ++

Private Sub  Something
   Dim strForm As String, strToFind As String
   strForm = "frmsinglewrlookup"
   strToFind = Nz(FieldIntheForm, "")

   'Open the form
   'strToFind is te open argument in the 2nd form
   DoCmd.OpenForm strForm, acNormal, , , , , strToFind

   'Move the focus to the second form
   DoCmd.SelectObject acForm, strForm

End Sub

In the Second From (Open Event):

Private Sub Form_Open(Cancel As Integer)
   Dim opnArg as String

   If IsNull(Me.Form.OpenArgs) Then
       Exit Sub
  Else
       opnArg = Me.Form.OpenArgs
       DoCmd.GoToControl "WORK_REQUEST_NO"
       DoCmd.FindRecord opnArg
   End If
   DoCmd.GoToControl     whatever
End Sub

|I am attempting to jump to a record, on a form open, using criteria supplied
| by the previous form.  I found an earlier discussion, on this topic, but was
[quoted text clipped - 24 lines]
|
| Sharkbyte
Sharkbyte - 22 May 2007 14:53 GMT
JK:

The code was perfect.  Thanks.  I was beginning to wonder if I hadn't
explained myself correctly.

Much appreciated.

Sharkbyte

> Hi, Sharkbyte,
>
[quoted text clipped - 99 lines]
> |
> | Sharkbyte
JK - 23 May 2007 07:39 GMT
My pleasure SharkByte,

I Forgot to mention:
If you have other routines in Open event of the second form, make sure that
my routine is *the last* one, otherwise other routines will not run when you
open that form in other ways when OpenArgs is a Null value

Regards/JK

| JK:
|
[quoted text clipped - 108 lines]
| > |
| > | Sharkbyte
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.