Results 1 to 4 of 4
  1. #1
    jmk909er is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Location
    San Diego, CA
    Posts
    39

    form record selector not working

    This is a little hard to explain but here goes:
    I have frmInrto that displays a list of projects by project number, the text box is refered to as "Reference Number". When you click on the project number it opens a full record with details in frmProjects using this code and linking the "Reference Number":



    'Enables link in frmIntro to link to frmProjects and filters by Reference Number
    Private Sub Reference_Number_Click()
    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "frmProjects"

    stLinkCriteria = "[Reference Number]=" & "'" & Me![Reference Number] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    End Sub

    When the frmProject form opens I want to be able to use the record selector at the bottom to also go into next and previous records. The problem is that with it being filtered by reference number it just shows 1 record in the selector. If I put code in "Me.Filter = no" after it loads it just goes to the first record and then shows all the records.

    Is there any way to have it load with the Reference Number selected and still be able to use the record selector to go to other records??

    Thanks, Joe

  2. #2
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Quote Originally Posted by jmk909er View Post
    This is a little hard to explain but here goes:
    I have frmInrto that displays a list of projects by project number, the text box is refered to as "Reference Number". When you click on the project number it opens a full record with details in frmProjects using this code and linking the "Reference Number":

    'Enables link in frmIntro to link to frmProjects and filters by Reference Number
    Private Sub Reference_Number_Click()
    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "frmProjects"

    stLinkCriteria = "[Reference Number]=" & "'" & Me![Reference Number] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    End Sub

    When the frmProject form opens I want to be able to use the record selector at the bottom to also go into next and previous records. The problem is that with it being filtered by reference number it just shows 1 record in the selector. If I put code in "Me.Filter = no" after it loads it just goes to the first record and then shows all the records.

    Is there any way to have it load with the Reference Number selected and still be able to use the record selector to go to other records??

    Thanks, Joe
    Joe,

    to clear the filter use:

    Code:
    Me.Filter = ""


    It is possible to open the form and then do a "find" then record and make it the current record.


    I prefer to use a combo box so that you can search by
    [Reference Number] but return the Primary key filed that is normally a number value (autonumber data type)

    I use the function placed in a code module:

    Code:
    Public Function bimOpenFormFindRec(pFormName As String, pControlToSearch As String, pFindThis As String, pIsNumeric As Boolean, Optional pOpenArgs As String) As Byte
    
        If pOpenArgs > "" Then
            DoCmd.OpenForm pFormName, , , , , , pOpenArgs
        Else
            DoCmd.OpenForm pFormName
         End If
    
        DoCmd.SelectObject A_FORM, pFormName
        DoCmd.GoToControl pControlToSearch
        
        If pIsNumeric Then
            DoCmd.FindRecord Val(pFindThis), A_ENTIRE, False, acSearchAll, False, A_CURRENT
        Else
            DoCmd.FindRecord pFindThis, A_ENTIRE, False, acSearchAll, False, A_CURRENT
        End If
        
        DoCmd.SelectObject A_FORM, pFormName
        DoCmd.GoToControl pControlToSearch
    
    End Function

    Last edited by HiTechCoach; 10-21-2010 at 08:20 AM.

  3. #3
    jmk909er is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Oct 2010
    Location
    San Diego, CA
    Posts
    39
    Thanks HiTechCoach, I think that Me.Filter = " " may be what I am looking for but I need more info. I am thinking I can make my own "Next" and "Previous" buttons on my form so that when I click on it, it removes the filter and goes to the next record, but when I include code for undoing the filter it goes to the first record on the table and not the next record.

    I tried the Me.Filter = " " that you gave me hoping that it would stay on the current record after the filter was removed but what happened is it errored out, if I take the space out between the quotes it works but exibits the same behavior as before, (removing the filter and going to the first record)

    I am by no means an expert, can you offer me anything else to go on?

    Thanks, Joe

  4. #4
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Joe,

    I use the function that I posted.

    To use place teh code in a new code module and then save it as modFormTools

    To use it you would substitute the Docmd.Open form line like this:

    Code:
    Private Sub Reference_Number_Click()
        Dim stDocName As String
        Dim stLinkCriteria As String
        stDocName = "frmProjects"
        
        stLinkCriteria = "[Reference Number]=" & "'" & Me![Reference Number] & "'"
        ' DoCmd.OpenForm stDocName, , , stLinkCriteria
    
    bimOpenFormFindRec  stDocName, "[Reference Number]", Me![Reference Number], False
    
    End Sub

    You could create a remove filter button that then also sues code similar to the function I gave you to retunr back to the record you were on before you removed the filter.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Add Record Button isn't working
    By tmcrouse in forum Forms
    Replies: 6
    Last Post: 08-02-2010, 02:09 PM
  2. Filter By Form not working!
    By Freybourne in forum Access
    Replies: 6
    Last Post: 06-22-2010, 09:41 PM
  3. Split Form not working correctly
    By Brian62 in forum Access
    Replies: 29
    Last Post: 02-16-2010, 05:43 PM
  4. Replies: 4
    Last Post: 05-12-2009, 01:50 PM
  5. Simple Nav Form Code Not Working
    By alsoto in forum Forms
    Replies: 10
    Last Post: 04-10-2009, 09:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums