Results 1 to 8 of 8
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Moving a form record selector (2003)

    I'm using the following code for the Click event of the cmdNext button on the startup form of the attached mdb in order to get the record selector in the Prev1 subform to move to the date corresponding to the one selected by clicking the cmdNext button but when I click the cmdNext button I get the error message: "Invalid reference to the bookmark property in the expression".
    <pre>Private Sub cmdNext_Click()
    Cdata = Cdata + 1
    Dim rst As Object
    On Error GoTo Err_cmdNext_Click
    Set rst = Me.Eventi.Form.Recordset.Clone
    rst.FindFirst "[Giorno] >= #" & Format(Me!Cdata, "mm/dd/yyyy") & "#"
    If Not rst.EOF Then Me.Bookmark = rst.Bookmark
    Exit_cmdNext_Click:
    Set rst = Nothing
    Exit Sub
    Err_cmdNext_Click:
    MsgBox Err.Description
    Resume Exit_cmdNext_Click
    End Sub</pre>


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Moving a form record selector (2003)

    Me refers to the main form. You want to move to a record in the subform, so you should use Me.Eventi.Form.Bookmark = ... instead of Me.Bookmark = ...

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Moving a form record selector (2003)

    Addition: you should use

    If Not rst.NoMatch Then

    instead of

    If Not rst.EOF Then

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving a form record selector (2003)

    Thank you Hans,
    I'm trying to make it so that if the date selected on the frmCalendarOCX form isn't in the Eventi table, then it gets added but when I click on the SAVE button on the frmCalendarOCX form after selecting a date, the code breaks at the line:
    <font color=red>rst.Open "eventi", cnn, adOpenKeyset, adLockOptimistic</font color=red>
    with the message:
    <font color=448800>Property or method not supported by the object.</font color=448800>

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Moving a form record selector (2003)

    You create rst implicitly as a DAO recordset, then close it and try to reopen it as an ADODB recordset. That is not possible. Since you start with DAO, you should stick to it.

  6. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving a form record selector (2003)

    Thank you Hans,
    now the date gets added but I can't make the record selector go to the date just added.
    I thought using
    <pre> Set rst = Forms!FDezzowithouttab.Eventi.Form.Recordset.Clone
    rst.FindFirst "[Giorno] >= #" & Format(Me!Calendar1, "mm/dd/yyyy") & "#"
    If Not rst.NoMatch Then Forms!FDezzowithouttab.Eventi.Form.Bookmark = rst.Bookmark
    rst.Close
    Set rst = Nothing</pre>


    again right after the statements that add the date to the Eventi table should do the job but it doesn't.

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Moving a form record selector (2003)

    Yep, that's necessary to let the form be "aware" of the new record.

  8. #8
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving a form record selector (2003)

    Found the solution <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    I just have to add
    <pre>Forms!FDezzowithouttab.Eventi.Form.Requery</pre>


    to the code in my previous post

Posting Permissions

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