Solved

Run-time error '13': Type mismatch    Me.Count

Posted on 2006-10-26
7
228 Views
Last Modified: 2012-08-13
Hi, There was a question asked by dkropacsy back on 1/15/2004.  It was answered by flavo.  

I found this answer when searching for questions re: MsgBox Err.Description  as I cannot seem to be able to change the coding in my form to allow me to modify the error message the user gets when they keep hitting the "Previous" command button I created using the command button wizard.

When reading the answer I found capricorn1 had responded and I would like to use his answer.  However, the code will not work and I believe it is because VB has changed in the past 2 3/4 years since he originally answered the question.  

When opening the form I get the error code I put in the title of this question.   Here is the code as I have modified it:
_________________________________________________________________________________
Private Sub Form_Load()
     
    Set rs = Me.RecordsetClone
    rs.MoveLast
    ' shows current record/total record count
    Me.Count = Me.CurrentRecord & "/" & rs.RecordCount  
    'On the previous line I changed capricorn1's  Me.txtRecCount to Me.Count.  This is what is highlighted when the debug window opens.
    rs.MoveFirst
    PreviousTeamMember.Enabled = False
    If rs.RecordCount > 1 Then
        NextTeamMember.Enabled = True
        Else
        NextTeamMember.Enabled = False
    End If
       
End Sub
_________________________________________________________________________________
Private Sub PreviousTeamMember_Click()
On Error GoTo Err_PreviousTeamMember_Click

    DoCmd.GoToRecord , , acPrevious
 
   Me.Count = Me.CurrentRecord & "/" & rs.RecordCount
    If Me.CurrentRecord = 1 And rs.RecordCount > 1 Then
        NextTeamMember.Enabled = True
        NextTeamMember.SetFocus
        PreviousTeamMember.Enabled = False
    End If
    If Me.CurrentRecord < rs.RecordCount Then
        NextTeamMember.Enabled = True
    End If

Exit_PreviousTeamMember_Click:
    Exit Sub

Err_PreviousTeamMember_Click:

    MsgBox Err.Description
         
    Resume Exit_PreviousTeamMember_Click
   
End Sub
_____________________________________________________________________________

What I was trying to do was change the error message dialog box that pops up when using the Previous command button (PreviousTeamMember).  Instead of it saying "Microsoft Office Access" in the dialog box title bar I want it to say "Whatever Database".  Instead of it saying "You can't go to the specifed record." in the dialog box (the prompt) I want it to say "You are at the first record.  There is no previous record to go to."

Also, when clicking on the Next command button (NextTeamMember), the form goes blank and then the same dialog box pops up again when the user clicks the Next command button again.  I want to change the error message as above, changing the word "Previous" to "Next".  

It would be great if a blank form did not appear when the user clicked on the "Next" button when the last Team Member has been reached.  Is there a way to prevent the form from going blank and having the error message pop up instead of going blank, and still having the Last Team member data loaded on the form?

0
Comment
Question by:amkazen
  • 4
  • 3
7 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 17815745

Me.txtRecCount  ' refers to a textbox in the form

ME.Count is a property of the form.

create a textbox and name it  txtRecCount
0
 

Author Comment

by:amkazen
ID: 17815777
LOL!  That worked.  Such a simple thing.  Shows how much I still do not know...a TON.  LOL

What about changing the error message?  Something simple there also? We can deal with the blank form after changing the error message, right?
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 250 total points
ID: 17815801
try revising this

Exit_PreviousTeamMember_Click:
    Exit Sub

Err_PreviousTeamMember_Click:

    'MsgBox Err.Description
       MsgBox "helloo............................................."  
    Resume Exit_PreviousTeamMember_Click
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:amkazen
ID: 17815979
I changed the error message as you said and it worked.  I then tried the following and it worked.
               MsgBox "helloo.............................................", , "My Title"
I was able to change the title.

Small problem, however:  "Our" above error message only appears after clicking "OK" on the original Access error message as it still appears, and appears before "our" error message.

Additionally, should the  txtRecCount  text box change as the records are scrolled through?  It only reads   1/5   as I only have 5 records of test data.


And now this.  Now when I click the NextTeamMember or PreviousTeamMember buttons I get a dialog error box saying "Object Required".  Also, I think I probably should have my command buttons named differently from my functions.  I had not realized I had done that until just now.  Maybe that is causing the problem, and if it is not it cannot be good programming.  I can remove the code below that I added (the if statements) and the Object Required dialog box goes away. Here is the code, and I am going home.  I need a break.
_____________________________________________________________
Private Sub Form_Load()
    Set rs = Me.RecordsetClone
    rs.MoveLast
    Me.txtRecCount = Me.CurrentRecord & "/" & rs.RecordCount ' shows current record/total record count
    rs.MoveFirst
    PreviousTeamMember.Enabled = False
    If rs.RecordCount > 1 Then
        NextTeamMember.Enabled = True
        Else
        NextTeamMember.Enabled = False
    End If
       
End Sub
______________________________________________________________

Private Sub NextTeamMember_Click()
On Error GoTo Err_NextTeamMember_Click

    DoCmd.GoToRecord , , acNext
    Me.txtRecCount = Me.CurrentRecord & "/" & rs.RecordCount
    If Me.CurrentRecord < rs.RecordCount Or Me.CurrentRecord > 1 Then
        PreviousTeamMember.Enabled = True
    End If
   
    If Me.CurrentRecord = rs.RecordCount Then
        PreviousTeamMember.SetFocus
        NextTeamMember.Enabled = False
    End If

Exit_NextTeamMember_Click:
    Exit Sub

Err_NextTeamMember_Click:
    MsgBox Err.Description
    MsgBox "helloo next............................", , "My Title"

    Resume Exit_NextTeamMember_Click
   
End Sub
_______________________________________________________________

Private Sub PreviousTeamMember_Click()
On Error GoTo Err_PreviousTeamMember_Click

    DoCmd.GoToRecord , , acPrevious
 
 Me.txtRecCount = Me.CurrentRecord & "/" & rs.RecordCount
    If Me.CurrentRecord = 1 And rs.RecordCount > 1 Then
        NextTeamMember.Enabled = True
        NextTeamMember.SetFocus
        PreviousTeamMember.Enabled = False
    End If
    If Me.CurrentRecord < rs.RecordCount Then
        NextTeamMember.Enabled = True
    End If
 
 Exit_PreviousTeamMember_Click:
    Exit Sub

Err_PreviousTeamMember_Click:

    MsgBox Err.Description
    MsgBox "helloo  previous.......................", , "My Title"
    Resume Exit_PreviousTeamMember_Click
   
End Sub





0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 17815993

   ' MsgBox Err.Description       <<<< i commented this line , do not include this line

    MsgBox "helloo  previous.......................", , "My Title"
    Resume Exit_PreviousTeamMember_Click
0
 

Author Comment

by:amkazen
ID: 17844182
Thanks, capricorn1!
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 17844204
U R Welcome!!!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now