open all record in form (1 Viewer)

hardik_088

Registered User.
Local time
Today, 15:07
Joined
May 31, 2011
Messages
82
hi guys,
I have SearchLaptops form that contain sub form "SubLaptops" and i have button in SerachLaptops form. when I click it it will find data and show me in SubLaptops form and when i click on record selector of SubLaptops I want to open Laptops form that is bound with Laptops table.And I want that Laptops form should show me all record that are in my SubLaptops form and when Laptops form will open i want to display that specific record where i clicked in record selector of SubLaptops. what i should do for this task.

serial number is primary key
-----------------
code in my SubLaptops form is here
---------------------
Option Compare Database
Option Explicit

Private Sub Form_DblClick(Cancel As Integer)
Dim frm As Form

For Each frm In Forms
If frm.Name = "Laptops" Then Exit For
Next frm
If frm.Name <> "Laptops" Then
Call DoCmd.OpenForm("Laptops", acNormal)
DoEvents
Set frm = Forms("Laptops")
End If
Call frm.SelectMe(me.serial number)

End Sub

----------------
Code in Laptops form is here
----------------
Option Compare Database
Option Explicit

Public Sub SelectMe(lngID As Long)
With Me.Recordset
.Index = Me.[serial number]
Call .Seek("=", lngID)
End With
End Sub

Thanks a lot
 
Last edited:

VilaRestal

';drop database master;--
Local time
Today, 23:07
Joined
Jun 8, 2011
Messages
1,046
The first sub looks a bit messed up I'm afraid. I think I can see what it's trying to do. I think this code would do it:

Code:
Private Sub Form_DblClick(Cancel As Integer)
    On Error Resume Next 'Incase Laptops form is already open
    DoCmd.OpenForm "Laptops"
    Forms!Laptops.SelectMe me![serial number]
End Sub
 

hardik_088

Registered User.
Local time
Today, 15:07
Joined
May 31, 2011
Messages
82
hi have tried that also and it is working but problem is that i want to open that form in when it open i want to see that record

example... if i find 10 records in my subform "SubLaptops" and if i click on record number 5 on record selector , it should open laptops form and record number five should display in the starting of form and all other data 10 records too when i click next or previous.

thanks a lot
 

hardik_088

Registered User.
Local time
Today, 15:07
Joined
May 31, 2011
Messages
82
so i have tried this code and it open that specific record but not other record in sub form have.

Private Sub Form_DblClick(Cancel As Integer)
On Error GoTo Err_Form_Click
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Laptops"

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

Exit_Form_Click:
Exit Sub

Err_Form_Click:
MsgBox Err.Description
Resume Exit_Form_Click
End Sub

thanks
 

VilaRestal

';drop database master;--
Local time
Today, 23:07
Joined
Jun 8, 2011
Messages
1,046
My code was very different to that


If SelectMe is working then that's what it should do (there's no where clause on the OpenForm command)
 

VilaRestal

';drop database master;--
Local time
Today, 23:07
Joined
Jun 8, 2011
Messages
1,046
Here's the two subs as I would do them:


Code:
Private Sub Form_DblClick(Cancel As Integer)
    On Error Resume Next 'Incase Laptops form is already open
    DoCmd.OpenForm "Laptops"
    Forms!Laptops.SelectMe me![serial number]
End Sub

Code:
Public Sub SelectMe(lngID As Long)
    Dim rsMe As Recordset
    Set rsMe = Me.Recordset
    rsMe.Find "[serial number] = " & lngID
    Set rsMe = Nothing
End Sub
 

hardik_088

Registered User.
Local time
Today, 15:07
Joined
May 31, 2011
Messages
82
Thanks dear,
but i tried that code and i put selectme() function in my laptops form
but it is giving error that method or data memeber not found in bold text
Public Sub SelectMe(lngID As Long) Dim rsMe As Recordset Set rsMe = Me.Recordset rsMe.Find "[serial number] = " & lngID Set rsMe = NothingEnd Sub
and if i put select me() function in SubLaptops form then it opens laptops form but it is always starting with first record and it is showing all record that are in my table laptops because Laptop from is bound with laptops table
 

VilaRestal

';drop database master;--
Local time
Today, 23:07
Joined
Jun 8, 2011
Messages
1,046
My mistake (used to ADO recordsets)

It should be
Code:
Public Sub SelectMe(lngID As Long)
    Dim rsMe As Recordset
    Set rsMe = Me.Recordset
    rsMe.[B]FindFirst[/B] "[serial number] = " & lngID
    Set rsMe = Nothing
End Sub
 

hardik_088

Registered User.
Local time
Today, 15:07
Joined
May 31, 2011
Messages
82
Thank you very much dear
its works nicely but
here i can see that specific record and all other data in my laptops table but i exactly want that is only that data i want to see that i find in my sub form "SubLaptops" not whole table data. if you can then great otherwise its ok
 

VilaRestal

';drop database master;--
Local time
Today, 23:07
Joined
Jun 8, 2011
Messages
1,046
Then I think the first sub should be:

Code:
Private Sub Form_DblClick(Cancel As Integer)
    On Error Resume Next 'Incase Laptops form is already open
    DoCmd.OpenForm "Laptops"
    With Forms!Laptops
        .Filter = Me.Filter
        .FilterOn = True
        .SelectMe me![serial number]
    End With
End Sub
 

hardik_088

Registered User.
Local time
Today, 15:07
Joined
May 31, 2011
Messages
82
Thanks dear
I have just changed bold text and its work perfectly that i want

Private Sub Form_DblClick(Cancel As Integer)
On Error Resume Next 'Incase Laptops form is already open
DoCmd.OpenForm "SubLaptops"
With Forms!Laptops
.Filter = Me.Filter
.FilterOn = True
.SelectMe me![serial number]
End With
End Sub
cheerssssssssssssssssssssssssssssss!!!!!!
Great!!!!!!!!!
 

Users who are viewing this thread

Top Bottom