dbTalk Databases Forums  

jump to a record in a datasheet form

comp.databases.ms-access comp.databases.ms-access


Discuss jump to a record in a datasheet form in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Co
 
Posts: n/a

Default jump to a record in a datasheet form - 10-06-2010 , 09:58 AM






Hi All,

I have a form(A) and subform(B).
Form B is a Datasheet form containing records. One of the fields is a
unique number and
consists of the year followed by a category number. For example:
2007-45

Now my database holds records from 2001 until now.
I would like to have a popup form with the years 2001 to 2010.
And when I click on a year the popup form dissapears and formB jumps
to the first record
of that year. This record should be projected at the top of the form.

Does anyone know how to do this or has a sample for me?

Regards
Marco

Reply With Quote
  #2  
Old   
Salad
 
Posts: n/a

Default Re: jump to a record in a datasheet form - 10-06-2010 , 12:47 PM






Co wrote:
Quote:
Hi All,

I have a form(A) and subform(B).
Form B is a Datasheet form containing records. One of the fields is a
unique number and
consists of the year followed by a category number. For example:
2007-45

Now my database holds records from 2001 until now.
I would like to have a popup form with the years 2001 to 2010.
And when I click on a year the popup form dissapears and formB jumps
to the first record
of that year. This record should be projected at the top of the form.

Does anyone know how to do this or has a sample for me?

Regards
Marco
In your main form I might have a dropdown. This is a sample row source.
SELECT DISTINCT CStr(Year(YourDateFieldName))AS Year, _
2 AS SortVar FROM YourTableName
UNION
SELECT "All" As Year, 1 As SortVar From YourTableName
Order By 2, 1 Desc

I selected unique years from the table so only valid years are
selected/presented. Since the first sort is on SortVar the word "ALL"
floats to the top and I ordered 1 Desc so that the most current year
floats to the second row, oldest year to the last row.

I might use a filter and display only records for a particular year in
the subform. In the AfterUpdate event I might use
Dim strF As String
If Me.ComboYear <> "ALL" then
strF = "Year(YourDateFieldName) = " & Me.ComboYear
Endif
Me.SubFormName.Form.Filter = strF 'set the filter
Me.SubFormName.Form.Filter = (strF <> "") 'turn filter on/off


Me.YourSubFormName.Form.Filter = _

Reply With Quote
  #3  
Old   
Co
 
Posts: n/a

Default Re: jump to a record in a datasheet form - 10-06-2010 , 01:05 PM



On 6 okt, 19:47, Salad <sa... (AT) oilandvinegar (DOT) com> wrote:
Quote:
Co wrote:
Hi All,

I have a form(A) and subform(B).
Form B is a Datasheet form containing records. One of the fields is a
unique number and
consists of the year followed by a category number. For example:
2007-45

Now my database holds records from 2001 until now.
I would like to have a popup form with the years 2001 to 2010.
And when I click on a year the popup form dissapears and formB jumps
to the first record
of that year. This record should be projected at the top of the form.

Does anyone know how to do this or has a sample for me?

Regards
Marco

In your main form I might have a dropdown. *This is a sample row source..
* *SELECT DISTINCT CStr(Year(YourDateFieldName))AS Year, _
* * *2 AS SortVar FROM YourTableName
* *UNION
* *SELECT "All" As Year, 1 As SortVar From YourTableName
Order By 2, 1 Desc

I selected unique years from the table so only valid years are
selected/presented. *Since the first sort is on SortVar the word "ALL"
floats to the top and I ordered 1 Desc so that the most current year
floats to the second row, oldest year to the last row.

I might use a filter and display only records for a particular year in
the subform. *In the AfterUpdate event I might use
* * * * Dim strF As String
* * * * If Me.ComboYear <> "ALL" then
* * * * * *strF = "Year(YourDateFieldName) = " & Me.ComboYear
* * * * Endif
* * * * Me.SubFormName.Form.Filter = strF *'set the filter
* * * * Me.SubFormName.Form.Filter = (strF <> "") *'turn filter on/off

* * * * Me.YourSubFormName.Form.Filter = _
I Put following code in the subform.

Public Function FindNaam(vName As Variant) As Boolean

Dim sCriteria As String
Dim sName As String
Dim rRs As DAO.Recordset
Dim iPos As Integer
On Error GoTo HandleErr

' Init
FindName = True
' Move to First record if Null
If IsNull(vName) Then
Me.Recordset.MoveFirst
Exit Function
End If
' Parse Name
sName = CStr(Nz(vName, ""))
sName = Replace(sName, "'", "''")
If Right(sName, 1) <> "*" Then
sName = sName & "*"
End If
' Criteria - use Like comparison
sCriteria = "[mynumber] Like '" & sName & "'"

' Search Clone
Set rRs = Me.RecordsetClone
With rRs
..FindFirst sCriteria
iPos = .AbsolutePosition
If .NoMatch Then
FindName = False
Beep
Else
FindName = True
mynumber.SetFocus
Me.SelTop = iPos + 1
Me.Recordset.Bookmark = rRs.Bookmark
' Force Scroll to selected Record
' Control must be able to recieve focus


End If
End With

Exit Function

HandleErr:
Err.Raise Number:=Err.Number, _
Description:=Err.Description, _
Source:="Form_MyForm.FindName" & vbCr & Err.Source
Exit Function

End Function

This code finds the first record from a certain year.
The problem is that I want to have this record at the top of the
subform.

I think it can be done with SelTop and .AbsolutePosition but I'm not
sure how.

MArco

Reply With Quote
  #4  
Old   
Salad
 
Posts: n/a

Default Re: jump to a record in a datasheet form - 10-06-2010 , 01:36 PM



Co wrote:

Quote:
On 6 okt, 19:47, Salad <sa... (AT) oilandvinegar (DOT) com> wrote:

Co wrote:

Hi All,

I have a form(A) and subform(B).
Form B is a Datasheet form containing records. One of the fields is a
unique number and
consists of the year followed by a category number. For example:
2007-45

Now my database holds records from 2001 until now.
I would like to have a popup form with the years 2001 to 2010.
And when I click on a year the popup form dissapears and formB jumps
to the first record
of that year. This record should be projected at the top of the form.

Does anyone know how to do this or has a sample for me?

Regards
Marco

In your main form I might have a dropdown. This is a sample row source.
SELECT DISTINCT CStr(Year(YourDateFieldName))AS Year, _
2 AS SortVar FROM YourTableName
UNION
SELECT "All" As Year, 1 As SortVar From YourTableName
Order By 2, 1 Desc

I selected unique years from the table so only valid years are
selected/presented. Since the first sort is on SortVar the word "ALL"
floats to the top and I ordered 1 Desc so that the most current year
floats to the second row, oldest year to the last row.

I might use a filter and display only records for a particular year in
the subform. In the AfterUpdate event I might use
Dim strF As String
If Me.ComboYear <> "ALL" then
strF = "Year(YourDateFieldName) = " & Me.ComboYear
Endif
Me.SubFormName.Form.Filter = strF 'set the filter
Me.SubFormName.Form.Filter = (strF <> "") 'turn filter on/off

Me.YourSubFormName.Form.Filter = _


I Put following code in the subform.

Public Function FindNaam(vName As Variant) As Boolean

Dim sCriteria As String
Dim sName As String
Dim rRs As DAO.Recordset
Dim iPos As Integer
On Error GoTo HandleErr

' Init
FindName = True
' Move to First record if Null
If IsNull(vName) Then
Me.Recordset.MoveFirst
Exit Function
End If
' Parse Name
sName = CStr(Nz(vName, ""))
sName = Replace(sName, "'", "''")
If Right(sName, 1) <> "*" Then
sName = sName & "*"
End If
' Criteria - use Like comparison
sCriteria = "[mynumber] Like '" & sName & "'"

' Search Clone
Set rRs = Me.RecordsetClone
With rRs
.FindFirst sCriteria
iPos = .AbsolutePosition
If .NoMatch Then
FindName = False
Beep
Else
FindName = True
mynumber.SetFocus
Me.SelTop = iPos + 1
Me.Recordset.Bookmark = rRs.Bookmark
' Force Scroll to selected Record
' Control must be able to recieve focus


End If
End With

Exit Function

HandleErr:
Err.Raise Number:=Err.Number, _
Description:=Err.Description, _
Source:="Form_MyForm.FindName" & vbCr & Err.Source
Exit Function

End Function

This code finds the first record from a certain year.
The problem is that I want to have this record at the top of the
subform.

I think it can be done with SelTop and .AbsolutePosition but I'm not
sure how.

MArco
Don't know. Seems silly to me. I suppose you go could reset the
subform to go to the last record, bookmark it, then search for the
record you want and bookmark it. It wouldn't help with a list of
records with multiple years that can fit in the subform's view, only for
long lists.

Reply With Quote
  #5  
Old   
Marshall Barton
 
Posts: n/a

Default Re: jump to a record in a datasheet form - 10-07-2010 , 12:01 PM



Co wrote:
Quote:
I have a form(A) and subform(B).
Form B is a Datasheet form containing records. One of the fields is a
unique number and
consists of the year followed by a category number. For example:
2007-45

Now my database holds records from 2001 until now.
I would like to have a popup form with the years 2001 to 2010.
And when I click on a year the popup form dissapears and formB jumps
to the first record
of that year. This record should be projected at the top of the form.

Once you have navigated to the desired record, I think you
can use this to position the record in the form
http://www.lebans.com/setgetsb.htm

--
Marsh

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.