Compile error Type Mismatch error

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
563
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Code:
Private Sub cmdbtnDone_Click()    
    Dim r As Range, r1 As Range
    Dim SRfrm As String
    
    Set r = Range(RefEdit1)
    Set r1 = r(1)
    
[COLOR=#ff0000]    SRfrm = selectFilefrm.txtbxSelectFile.Value[/COLOR]
    
    Load Chattemfrm
    Chattemfrm.cmbSDPFLine.Value = ActiveWorkbook.Name
    Chattemfrm.cmbPrdCde.Value = r1.Offset(0, -6).Value
 
    Chattemfrm.txtBxLtNum.Value = r1.Offset(0, -3).Value
    Chattemfrm.txtBxShopNumber.Value = r1.Offset(0, 1).Value
    Chattemfrm.txtbxVndrLtNu.Value = r1.Offset(0, -2).Value
    Chattemfrm.txtbxdz = Me.txtbxRangeTotal.Value
        
    Select Case Chattemfrm.cmbSDPFLine.Value
        Case Is = "SDPF - LINE 1 (SLAT).xlsx"
            Chattemfrm.cmbSDPFLine.Value = "Slat"
        Case Is = "SDPF - LINE 2A.xlsx"
            Chattemfrm.cmbSDPFLine.Value = "Uhlmann"
        Case Is = "SDPF - LINE 3.xlsx"
            Chattemfrm.cmbSDPFLine.Value = "Korber"
        Case Is = "SDPF - LINE 4.xlsx"
            Chattemfrm.cmbSDPFLine.Value = "IMA"
    End Select
    
    Unload Me
[COLOR=#ff0000]    Load SRfrm[/COLOR]
    ActiveWorkbook.Close
    Chattemfrm.Show
    
End Sub
On the previous form. it allows the user to select a file that they want to open. That form is called selectfilefrm. This form is constructed with Label caption of Select File:, a text box with the name txtbxSelectFile, and two command buttons one named Browse and the other Open.
There are multiple workbooks that the user can choose to open to obtain the data needed. So rather than doing either an IF:Then statement or a Select case to close the form when done, it would be easier to just get the file name and location from the previous form selectfilefrm. Load it making it the activeworkbook and the next line would then close it.
Originally, I removed the Dim SRfrm As String and tried to use the Set statement and I left the rest of the code the same.
Code:
Set SRfrm = selectFilefrm.txtbxSelectFile.Value
Unfortunately, I then received a Run-time error '13' Type mismatch.
I hope my explanation really makes sense. Thank you all for your help.
 
Last edited:

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Does the code run if you change the line to:
Code:
[COLOR=#333333]Dim SRfrm As Variant[/COLOR]

?

This will tell us if its a variable problem or a code structure problem

Caleeco
 
Upvote 0
Maybe
Code:
   Unload Me
   [COLOR=#0000ff]Workbooks.Open SRfrm[/COLOR]
   ActiveWorkbook.Close
 
Upvote 0

Forum statistics

Threads
1,215,514
Messages
6,125,265
Members
449,219
Latest member
daynle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top