Why would I get a 'type mismatch' on this line?

Why would I get a type mismatch on this line?

shipcurrency = .Cells(14,4).Value

carrier = .Cells(8,4).Value

country = .Cells(row,8).Value

provstate = .Cells(row,2).Value

city = .Cells(row,1).Value

keylook = Trim(carrier) + Trim(country) + Trim(provstate) + Trim(city) + Trim(Left(fromplant,2))

Set viewdoc = view.Getdocumentbykey(keylook,True)

If viewdoc Is Nothing Then this line here

Print "Importing… " & city & ", " & provstate

The keylook has a value.

Thanks people

KB

Subject: Why would I get a ‘type mismatch’ on this line?

did you declare viewdoc ?i did not see the line dim viewdoc as notesdocument

Subject: RE: Why would I get a ‘type mismatch’ on this line?

Hey thanks for the responses guys. I just found out that it’s crapping out on a different line. See below. One is showing as a variant and the other as a Long type.

Sub Click(Source As Button)

Dim ws As New NotesUIWorkspace

Dim session As New NotesSession

Dim db As NotesDatabase

Dim contactdb As NotesDatabase

Dim Excel As Variant

Dim xlWorkbook As Variant

Dim xlSheet As Variant

Dim xlFilename As Variant

Dim row As Long

Dim count As Long

Dim doc As NotesDocument

Dim thisdoc As NotesUIDocument

Dim view As NotesView

Dim viewdoc As NotesDocument

Dim canadianrate As Variant

Dim americanrate As Variant

Dim thisyear As Variant

Dim thismonth As Variant



Set thisdoc = ws.CurrentDocument

Set db = session.CurrentDatabase	

Set view = db.GetView("(ratelookup)")

canadianrate = thisdoc.document.CadRate(0)

americanrate = thisdoc.document.USRate(0)

thisyear = thisdoc.Document.Year(0)

thismonth = thisdoc.Document.Month(0)



xlFilename = ws.OpenFileDialog(False,"File To Import","MS Excel Documents|*.xls|All Files|*.*","S:\APT\Freight")

If Isempty (xlFilename) Then

	Exit Sub

End If

'Import the records

Print "Connecting to Excel..."

Set Excel = CreateObject( "Excel.Application" )

Excel.Visible = False 

Excel.Interactive = False

Print "Opening " & xlFilename(0) & "..."

Excel.Workbooks.Open xlFilename 

Set xlWorkbook = Excel.ActiveWorkbook

Set xlSheet = xlWorkbook.ActiveSheet



row = 17 

count = 0



Print "Starting import from Excel file..."



With xlSheet

	Do While .Cells(row, 1).Value <> "" 

		'Gets the field contents of the first document in the view	

		baserate = .Cells(row,5).Value

		fromplant = .Cells(9,1).Value

		If baserate = "" Then

			row = row + 1

		Else

			

			shipcurrency = .Cells(14,4).Value

			carrier = .Cells(8,4).Value			

			country = .Cells(row,8).Value				

			provstate = .Cells(row,2).Value				

			city = .Cells(row,1).Value

			

			keylook = Trim(carrier) + Trim(country) + Trim(provstate) + Trim(city)  + Trim(Left(fromplant,2))

			

			Set viewdoc = view.Getdocumentbykey(keylook,True)

			

			If   viewdoc Is Nothing Then

				

				Print "Importing... " & city & ", " & provstate

				Set doc = db.CreateDocument 	

				doc.Form = "Freight Quote"

				doc.Country = country

				doc.Carrier = .Cells(8,4).Value

				doc.ProvState = .Cells(row, 2).Value

				doc.City = .Cells(row, 1).Value

				doc.PostalZip = .Cells(row, 3).Value

				doc.FSCamt = .Cells(row,6).Value

				doc.FromPlant = .Cells(9, 1).Value

				doc.BaseRate = baserate

				doc.Miles = .Cells(row, 4).Value

				doc.CarrierRating = contactitem

				doc.Year = thisyear

				doc.Month = thismonth

				

				If shipcurrency = "USD$" Then

					doc.rdoCurrency = "USD$"

					doc.BRusd= baserate

					doc.BRcad = Round(baserate * americanrate,2)			

				Else

					doc.rdoCurrency = "CAD$"

					doc.BRcad= baserate

					doc.BRusd = Round(baserate * canadianrate,2)

				End If

				

				Call doc.ComputeWithForm(True, False) 'Refresh values of computed fields not set here

				Call doc.Save( True, True ) 

				count = count + 1

				row = row + 1

				

			Else

				If viewdoc.BaseRate <> baserate Then  ***this line***

					

					viewdoc.Miles = .Cells(row, 4).Value

					viewdoc.BaseRate = baserate

					Call viewdoc.ComputeWithForm(True,False)

					Call viewdoc.Save(True,True)

					count = count + 1

					row = row + 1

				Else

					row = row + 1

				End If

			End If

		End If

	Loop

	

	

End With



Print "Disconnecting from Excel..."

xlWorkbook.Close False 

Excel.Quit

Set Excel = Nothing 

End Sub

Thanks again for looking

KB

Subject: RE: Why would I get a ‘type mismatch’ on this line?

As you said, one is a variant which can have multiple values. The likely simple solution is:

If viewdoc.BaseRate(0) <> baserate Then

Subject: RE: Why would I get a ‘type mismatch’ on this line?

Yep that was it!! Thanks alot and I appreciate the help

KB

Subject: Why would I get a ‘type mismatch’ on this line?

Have you declared viewdoc?

Have you possibly used viewdoc earlier?

It’s important to declare it as it’s possible the script has assumed it another datatype which cannot be Nothing. For example, maybe the system is expecting it to be a string.

If you use the debugger you could see what it was expecting.