Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2004
    Location
    Australia
    Posts
    183

    Arrow Unanswered: Click to open a specific record

    Hello guys,

    This is the code that I use to double click on text box displaying certain data that calls the function that will go to a particular form/screen and open it displaying data relevant for that record

    Private Sub Text40_DblClick(Cancel As Integer)

    Dim ctl As Control
    Dim frm As Form

    Set frm = Forms!frmSearchFileRegister
    Set ctl = frm!Text40

    Call OpenEdit_ARegisterEntry(ctl.Text)

    End Sub

    But in stead of doing this I have a command button and would like to do the same thing by clicking on the button,it opens the relevant form with relevant data,but when I do that this is the error message I get and highlights the line of code

    error: object doesn't support this property or method
    Call OpenEdit_ARegisterEntry(ctl.Text)

    which property do I need to assign to my control(that being a command button) in order for this to work, anybody.

    Thanks heaps

  2. #2
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    243

    Re: Click to open a specific record

    Originally posted by zobernjik
    Hello guys,

    This is the code that I use to double click on text box displaying certain data that calls the function that will go to a particular form/screen and open it displaying data relevant for that record

    Private Sub Text40_DblClick(Cancel As Integer)

    Dim ctl As Control
    Dim frm As Form

    Set frm = Forms!frmSearchFileRegister
    Set ctl = frm!Text40

    Call OpenEdit_ARegisterEntry(ctl.Text)

    End Sub

    But in stead of doing this I have a command button and would like to do the same thing by clicking on the button,it opens the relevant form with relevant data,but when I do that this is the error message I get and highlights the line of code

    error: object doesn't support this property or method
    Call OpenEdit_ARegisterEntry(ctl.Text)

    which property do I need to assign to my control(that being a command button) in order for this to work, anybody.

    Thanks heaps

    Put in the click-event of the button :

    Code:
    private sub cmdMyButton_Click()
       Call Text40_DblClick(cancel)
    end sub

  3. #3
    Join Date
    Feb 2004
    Location
    Australia
    Posts
    183

    Re: Click to open a specific record

    Originally posted by artemide
    Put in the click-event of the button :

    Code:
    private sub cmdMyButton_Click()
       Call Text40_DblClick(cancel)
    end sub

    Hello Artemide,

    Thanks for you help, but what do I define Cancel as anyway.

  4. #4
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    243

    Re: Click to open a specific record

    Originally posted by zobernjik
    Hello Artemide,

    Thanks for you help, but what do I define Cancel as anyway.

    I forgot a part.
    When you make a click-event it will automatically get Cancel as parameter

    Code:
    private sub cmdMyButton_Click(Cancel as Integer)
       Call Text40_DblClick(cancel)
    end sub
    It will pass that one through to the txt-event.

    I'm not 100% sure it's the right way, but it works for me

  5. #5
    Join Date
    Feb 2004
    Location
    Australia
    Posts
    183
    Yes I can see what you are trying to do but it doesn't seem to work for me,

    Will give a deeper thought.

    Thanks

  6. #6
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    243
    Originally posted by zobernjik
    Yes I can see what you are trying to do but it doesn't seem to work for me,

    Will give a deeper thought.

    Thanks
    Try this one :
    The textfield expects an integer, so we give it one.
    Most of the time zero (0) means that everything is OK, so I don't think it will be of any harm here.

    Code:
    private sub cmdMyButton_Click()
       Call Text40_DblClick(0)
    end sub

  7. #7
    Join Date
    Feb 2004
    Location
    Australia
    Posts
    183
    Thanks for your help once again but it is saying I have to set the focus on the control before doing anything with it and I try using "GoToConrol" or "SetFocus" but just keep getting invalid property assign errors.

    Any ideas

  8. #8
    Join Date
    Sep 2001
    Location
    Chicago, Illinois, USA
    Posts
    601
    Why aren't you just using:

    DoCmd.OpenForm "A_Form_Name", . . . . . . .

  9. #9
    Join Date
    Feb 2004
    Location
    Australia
    Posts
    183
    I did try but it was taking me to that form but not opening the particular record I need.

    Yeah, will have a look at that again

    Thanks

  10. #10
    Join Date
    Mar 2004
    Location
    GTA, Ontario, Canada
    Posts
    1

    does this get you there?

    I've done this before by first setting up the form I want to open to a specific record with the code that moves the form to a specific record using a combobox (access will make this for you) something like:

    Sub cboRecordID_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object

    Set rs = Me.RecordsetClone
    rs.FindFirst "[RecordID] = " & Str(Nz(Me![cboRecordID], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    End Sub

    then with your button on the first form do something like:

    Private Sub btn1_Click()

    Dim stDocName As String

    stDocName = "frmShowRecord"


    DoCmd.OpenForm stDocName

    Form_frmShowRecord.cboRecordID = Me![RecordID]
    Form_frmShowRecord.SetFocus
    Form_frmShowRecord.cboRecordID_AfterUpdate

    End Sub

    I think that will get you where you want to go.

  11. #11
    Join Date
    Dec 2003
    Posts
    268

    If there is more than one report

    You can hit a table to pull the form for the respective situation, then you can use the code listed earlier to apply the filter.

    set rs = db.openrecordset ("SELECT tblName, FilterName FROM tblTableList WHERE tblName = " & your tablenamehere "

    Then hit the two columns for the data
    strfilter = rs.fields(1)
    strFormName = rs.fields(0)

    docmd.openform strFormName, acNormal, strFilter, cboRecordID

    you can also do it like this
    ....from after the declaration of the rs

    docmd.openform rs.fields(0), rs.fields(1), acNormal, cboRecorID

    That too will work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •