Type Mismatch issue

Great Day, I have created a table that I am placing my help files in, and it has the following fields:

HelpFileID - Autonumber (KF)
HelpSubject - Text
HelpFile - Memo

On every form that has a help button, I place an unbound text box, txtHelpID that is defaulted with the number of the help file I'd like to display in a popup form. Consequently, if for example I have a help button on my customers form, when it opens, txtHelpID will have a 3 in it, since the help file in tblHelpFiles for customers has 3 as its ID. So to me, everything seems to match, but when I click the "Help" button, I get the following error message: "Text mismatch."

Here is the code that opens the popup help form:
Private Sub cmdHelp_Click()
On Error GoTo Err_cmdHelp_Click

    Dim stDocName As String
    Dim stLinkCriteria As Integer

    stDocName = "frmHelpFiles"
    stLinkCriteria = "[HelpFileID]=" & Me.txtHelpID
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    
Exit_cmdHelp_Click:
    Exit Sub

Err_cmdHelp_Click:
    MsgBox Err.Description
    Resume Exit_cmdHelp_Click
    
End Sub

Open in new window

yddadsjd95Asked:
Who is Participating?
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
ok ... found the issue  Don't Dim as Long ... see bold below


Private Sub cmdHelp_Click()
On Error GoTo Err_cmdHelp_Click

    Dim stDocName As String
    Dim stLinkCriteria   'As Long
    stDocName = "frmHelpFiles"
   
'    stLinkCriteria = "[HelpFileID]=" & CLng(Me.txtHelpID)
    stLinkCriteria = "[HelpFileID]=" & Me.txtHelpID
    DoCmd.OpenForm stDocName, , , stLinkCriteria
   
Exit_cmdHelp_Click:
    Exit Sub

Err_cmdHelp_Click:
    MsgBox Err.Description
    Resume Exit_cmdHelp_Click
   
End Sub
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
What happens if you do this:


stLinkCriteria = "[HelpFileID]=" & Clng(Me.txtHelpID)

or

stLinkCriteria = "[HelpFileID]=" & Chr(34) &  Me.txtHelpID & Chr(34)

mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
: "Text mismatch."  or Type Mismatch ?

mx
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
yddadsjd95Author Commented:
My mistake, but it is Type Mismatch. I am still getting the same error (Type mismatch).
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
can you upload the db?

mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
And did you try this one:

stLinkCriteria = "[HelpFileID]=" & Clng(Me.txtHelpID)

mx
0
 
yddadsjd95Author Commented:
Yes I tried both ways. I'll send the DB to you.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Yes. please do ... :-)
0
 
yddadsjd95Author Commented:
Here it is. Thanks!

1.Open frmCustomerContactData 2. Click "Print Repair Order" 3. Click "Open Invoice" 4. Click Help
Independent-Auto---EE-10-19-2011.zip
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
This also works:


Private Sub cmdHelp_Click()
On Error GoTo Err_cmdHelp_Click

    Dim stDocName As String
   Dim stLinkCriteria As String
    stDocName = "frmHelpFiles"
   
    stLinkCriteria = "[HelpFileID]=" & CLng(Me.txtHelpID)
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdHelp_Click:
    Exit Sub

Err_cmdHelp_Click:
    MsgBox Err.Description
    Resume Exit_cmdHelp_Click
   
End Sub
0
 
yddadsjd95Author Commented:
Thank you DatabaseMX. Very few things in life give me more satisfaction than to see a problem in Access worked out. You've made my night.

Have a great rest of the evening.

Sincerely,

David
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Always a pleasure.

I think it's because a value in at Text box is cast as ... well, text. So ... because the Dim was As Long ... there was an immediate error on that line of code - which at first I was going ... WTH ..?

So, the only thing it could have been was the Dim statement.

mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
In reality ... the code can be boiled down to this:


Private Sub cmdHelp_Click()

    DoCmd.OpenForm "frmHelpFiles", , , Me.txtHelpID

End Sub

Just be sure you always have something in txtHelpID.

mx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.