Results 1 to 4 of 4
  1. #1
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276

    Help Me Fix the Code

    Need Help fixing the code
    When I select the Company Name It should show me the last record whereas by using the following code does not do that
    where am I making a mistake


    Private Sub Combo28_Exit(Cancel As Integer)
    If Combo28.Text = "" Then


    Cancel = True
    End If
    If Combo28.Value = "" Or IsNull(Combo28.Value) Then
    MsgBox ("Select Company Name To Proceed !!!")
    Cancel = True
    Else
    Dim rs As Object


    Set rs = Me.Recordset.Clone
    rs.FindFirst "[CoId] = " & Str(Me![Combo28])
    Me.Bookmark = rs.Bookmark


    End If
    End Sub




    Thanks & Regards
    Aamer

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Not sure I would use the EXIT event. I would use the AfterUpdate event.
    Maybe this??
    Code:
    Sub Combo28_AfterUpdate()
    
        If Combo28.Text = "" Then   '<<-- not sure why you are using the TEXT property
            Cancel = True
        End If
    
        If Combo28.Value = "" Or IsNull(Combo28.Value) Then
            MsgBox ("Select Company Name To Proceed !!!")
            Cancel = True
        Else
    
            Dim rst As DAO.Recordset
    
            Set rst = Me.RecordsetClone  ' NOT Me.Recordset.Clone - see the difference???
    
            'if CoID is a number
            rst.FindFirst "CoID = " & Me![Combo28]
    
            'if CoID is Text, comment out the previous line and uncomment the next
    '        rst.FindFirst "CoID = '" & Me![Combo28] & "'"
    
            'check to see if a record is found
            If rst.NoMatch Then   'ALWAYS check the NoMatch property after a FindFirst
                MsgBox "Record not found"
            Else
                Me.Bookmark = rst.Bookmark
            End If
    
            'clean up
            rst.Close
            Set rst = Nothing
        End Sub

  3. #3
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    This code is not working it does not show previous record

    It gives the following error


    Compile error:


    User-defined type not defined


    following is highlighted in VB


    rst As DAO.recoredset

  4. #4
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    In the vb editor, Tools>References, set a reference to DAO by finding it in the long list and checking the box.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 20
    Last Post: 10-13-2015, 09:05 AM
  2. Replies: 3
    Last Post: 10-16-2014, 08:49 AM
  3. Replies: 7
    Last Post: 05-28-2013, 09:11 AM
  4. Replies: 1
    Last Post: 05-04-2013, 12:19 PM
  5. Word code in Access - How to modify my current code
    By Alexandre Cote in forum Programming
    Replies: 0
    Last Post: 11-15-2010, 08:26 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