Results 1 to 2 of 2
  1. #1
    hnhpak is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jan 2015
    Location
    Karachi Pakistan
    Posts
    28

    DoCmd.SearchForRecord , , acGoTo, "ID =" & Me.CBO_STD_ID

    I am using following code and want to go to the record where condition ID=[Screen][Active Control] through a ComboBox


    Private Sub CBO_STD_ID_AfterUpdate()

    If IsNull([Screen].ActiveControl) Then
    DoCmd.GoToControl "[CBO_STD_ID]"
    End If

    varActContVal = [Screen].ActiveControl


    DoCmd.GoToRecord , , acGoTo, Screen.ActiveControl

    End Sub

    Note:
    Screen.ActiveControl is the value input by unbounded comboBox.
    This the value of Filed ID of the table/Query rawsource of the form.

    I want to go to the record where condition ID=[Screen].[ActiveControl]

    The above mentioned code works well for first 39 records and then it react strangely and gives wrong results.

    On investigation into table it found that ID number form 1-39 are without break, then records having ID 40, 41,44,67,92,97,137,146,191 are deleted from table.

    Problem came onward from record having ID more then 39. Results are as under:

    on selection from 1-39 go to correct record
    on Selection ID 42 it goes to ID 45 two records forward
    on Selection ID 45 it goes to ID 48 three records forward
    on Selection ID 66 it goes to ID 70 four records forward
    on Selection ID 68 it goes to ID 72 five records forward
    On Selection ID 93 it goes to ID 104 six records forward .... and so on

    On selecting last 8 to 10 records a run time error message says ' You can not go to the specific record'
    I am unable to understand the behavior of database in this regards. If you understand please let me know how can i fix it.

    ID is the primary key of the table
    and records related to ID 40, 41,44,67,92,97,137,146,191 are deleted from table.

    What I understands from this behavior of comboBox record selection, it goes to record number serial from top,
    and whereas the value of
    Screen.ActiveControl is the ID number of primary key, which is higher then the serial number of the record due to deleted records in between.


    I therefore also had tried the code SearchForRecord with where condition as under
    DoCmd.SearchForRecord , , acGoTo, "ID =" & Me.CBO_STD_ID
    DoCmd.SearchForRecord , , acGoTo, "ID =" [Screen].[ActiveControl]

    instead of
    DoCmd.GoToRecord , , acGoTo, Screen.ActiveControl

    But all fails, a run time error message shows.

    Please help in this regards where i am doing mistake.

    Thanks and regards

    Haseebul Hasan

  2. #2
    hnhpak is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jan 2015
    Location
    Karachi Pakistan
    Posts
    28
    Hi All

    Matter has been resolved by using following code

    Private Sub CboSTD_AfterUpdate()
    Dim rs As DAO.Recordset


    If Not IsNull(Me.cboStd) Then
    'Save before move.
    If Me.Dirty Then
    Me.Dirty = False
    End If
    'Search in the clone set.
    Set rs = Me.RecordsetClone
    rs.FindFirst "[ID] = " & Me.cboStd
    If rs.NoMatch Then
    MsgBox "Not found: filtered?"
    Else
    'Display the found record in the form.
    Me.Bookmark = rs.Bookmark
    End If
    Set rs = Nothing
    End If
    End Sub

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

Similar Threads

  1. Replies: 3
    Last Post: 01-27-2015, 12:25 PM
  2. Where do I put DoCmd.Close acForm, "Email_AORB"?
    By Thompyt in forum Programming
    Replies: 3
    Last Post: 11-12-2014, 05:17 PM
  3. Replies: 2
    Last Post: 07-15-2014, 07:22 PM
  4. "DoCmd.GotoRecord" Help required
    By abusaif in forum Access
    Replies: 5
    Last Post: 12-19-2013, 12:25 AM
  5. Can I pass "sort by" using DoCmd.OpenReport
    By alsoto in forum Reports
    Replies: 3
    Last Post: 04-16-2009, 08:11 PM

Tags for this Thread

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