Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Type mismatch? string 2 a long??


I have a type mismatch and i can't understand why?

I have two textboxes on a form which i deduct from a given amount. Thi
works OK when both boxes have a value in them but just one box entere
& all go's the way of the Pear!?

I had t & t2 decalred as long but tried to get the thing working an
changed them to variants, this just shifted the blame further down
line or 2. My problem i think is due to textbox values being a string
how do i say the input will be a long? or even the cell for tha
matter?



Private Sub CommandButton1_Click()
N = FrmDor1.N
Dim t As Variant: Dim t2 As Variant
Dim note As String
Dim nt As String: Dim nt1 As String


If TextBox1.Value < "" Then
Sheets("Sheet1").Cells(N, 31) = TextBox1.Value
End If
If TextBox2.Value < "" Then
Sheets("Sheet1").Cells(N, 30) = TextBox2.Value
End If
If TextBox3.Value < "" Then
Sheets("Sheet1").Cells(N, 38) = TextBox3.Value
End If

If TextBox4.Value < "" Or TextBox5.Value < "" Then
t = TextBox4.Value 'pack left
t2 = TextBox5.Value 'pack right
If TextBox4.Value = "" Then
nt = ""
Else
nt = t & " left pack,"
End If

If TextBox5.Value = "" Then
nt1 = ""
Else
nt1 = t2 & " right pack,"
End If

note = Sheets("Sheet1").Cells(N, 23)
Sheets("Sheet1").Cells(N, 23) = note & " " & " " &nt& " "&nt1
FrmDor1.TextBox4.Value = note & " " & " " & nt & " " &nt1
'THIS is my problem line
Sheets("Sheet1").Cells(N, 31) = Sheets("Sheet1").Cells_
(N, 11) - t - t2
End If

End Sub

Thanks for even looking at this. Any help will be appreciated.
CA

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default Type mismatch? string 2 a long??

if NOT ( isnumeric(textbox4.value) and _
isnumeric(textbox4.value)) Then
msgbox "Text boxes must contain numbers!"
exit sub
End If
t =clng(TextBox5.Value) 'pack left
t2 = clng(TextBox5.Value) 'pack right



Patrick Molloy
Microsoft Excel MVP
-----Original Message-----

I have a type mismatch and i can't understand why?

I have two textboxes on a form which i deduct from a

given amount. This
works OK when both boxes have a value in them but just

one box entered
& all go's the way of the Pear!?

I had t & t2 decalred as long but tried to get the thing

working and
changed them to variants, this just shifted the blame

further down a
line or 2. My problem i think is due to textbox values

being a string,
how do i say the input will be a long? or even the cell

for that
matter?



Private Sub CommandButton1_Click()
N = FrmDor1.N
Dim t As Variant: Dim t2 As Variant
Dim note As String
Dim nt As String: Dim nt1 As String


If TextBox1.Value < "" Then
Sheets("Sheet1").Cells(N, 31) = TextBox1.Value
End If
If TextBox2.Value < "" Then
Sheets("Sheet1").Cells(N, 30) = TextBox2.Value
End If
If TextBox3.Value < "" Then
Sheets("Sheet1").Cells(N, 38) = TextBox3.Value
End If

If TextBox4.Value < "" Or TextBox5.Value < "" Then
t = TextBox4.Value 'pack left
t2 = TextBox5.Value 'pack right
If TextBox4.Value = "" Then
nt = ""
Else
nt = t & " left pack,"
End If

If TextBox5.Value = "" Then
nt1 = ""
Else
nt1 = t2 & " right pack,"
End If

note = Sheets("Sheet1").Cells(N, 23)
Sheets("Sheet1").Cells(N, 23) = note & " " & " "

&nt& " "&nt1
FrmDor1.TextBox4.Value = note & " " & " " & nt & " " &nt1
'THIS is my problem line
Sheets("Sheet1").Cells(N, 31) = Sheets("Sheet1").Cells_
(N, 11) - t - t2
End If

End Sub

Thanks for even looking at this. Any help will be

appreciated.
CAA


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from

http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by

step guide to creating financial statements
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Type mismatch? string 2 a long??

t = clng("0" & Trim(TextBox4.Value)) 'pack left
t2 = clng("0" & trim(TextBox5.Value)) 'pack right

also in your code where you have &, the & should have a space on each side.
if you do VarName&"t"

VarName& could be interpreted as the variable name rather than as a variable
name and concatenation operator.

--
Regards,
Tom Ogilvy

"CAA" wrote in message
...

I have a type mismatch and i can't understand why?

I have two textboxes on a form which i deduct from a given amount. This
works OK when both boxes have a value in them but just one box entered
& all go's the way of the Pear!?

I had t & t2 decalred as long but tried to get the thing working and
changed them to variants, this just shifted the blame further down a
line or 2. My problem i think is due to textbox values being a string,
how do i say the input will be a long? or even the cell for that
matter?



Private Sub CommandButton1_Click()
N = FrmDor1.N
Dim t As Variant: Dim t2 As Variant
Dim note As String
Dim nt As String: Dim nt1 As String


If TextBox1.Value < "" Then
Sheets("Sheet1").Cells(N, 31) = TextBox1.Value
End If
If TextBox2.Value < "" Then
Sheets("Sheet1").Cells(N, 30) = TextBox2.Value
End If
If TextBox3.Value < "" Then
Sheets("Sheet1").Cells(N, 38) = TextBox3.Value
End If

If TextBox4.Value < "" Or TextBox5.Value < "" Then
t = TextBox4.Value 'pack left
t2 = TextBox5.Value 'pack right
If TextBox4.Value = "" Then
nt = ""
Else
nt = t & " left pack,"
End If

If TextBox5.Value = "" Then
nt1 = ""
Else
nt1 = t2 & " right pack,"
End If

note = Sheets("Sheet1").Cells(N, 23)
Sheets("Sheet1").Cells(N, 23) = note & " " & " " &nt& " "&nt1
FrmDor1.TextBox4.Value = note & " " & " " & nt & " " &nt1
'THIS is my problem line
Sheets("Sheet1").Cells(N, 31) = Sheets("Sheet1").Cells_
(N, 11) - t - t2
End If

End Sub

Thanks for even looking at this. Any help will be appreciated.
CAA


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to

creating financial statements


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Type mismatch? string 2 a long??

t = clng("0" & Trim(TextBox4.Value)) 'pack left
t2 = clng("0" & trim(TextBox5.Value)) 'pack right

also in your code where you have &, the & should have a space on each side.
if you do VarName&"t"

VarName& could be interpreted as the variable name rather than as a variable
name and concatenation operator.

--
Regards,
Tom Ogilvy


"CAA" wrote in message
...

I have a type mismatch and i can't understand why?

I have two textboxes on a form which i deduct from a given amount. This
works OK when both boxes have a value in them but just one box entered
& all go's the way of the Pear!?

I had t & t2 decalred as long but tried to get the thing working and
changed them to variants, this just shifted the blame further down a
line or 2. My problem i think is due to textbox values being a string,
how do i say the input will be a long? or even the cell for that
matter?



Private Sub CommandButton1_Click()
N = FrmDor1.N
Dim t As Variant: Dim t2 As Variant
Dim note As String
Dim nt As String: Dim nt1 As String


If TextBox1.Value < "" Then
Sheets("Sheet1").Cells(N, 31) = TextBox1.Value
End If
If TextBox2.Value < "" Then
Sheets("Sheet1").Cells(N, 30) = TextBox2.Value
End If
If TextBox3.Value < "" Then
Sheets("Sheet1").Cells(N, 38) = TextBox3.Value
End If

If TextBox4.Value < "" Or TextBox5.Value < "" Then
t = TextBox4.Value 'pack left
t2 = TextBox5.Value 'pack right
If TextBox4.Value = "" Then
nt = ""
Else
nt = t & " left pack,"
End If

If TextBox5.Value = "" Then
nt1 = ""
Else
nt1 = t2 & " right pack,"
End If

note = Sheets("Sheet1").Cells(N, 23)
Sheets("Sheet1").Cells(N, 23) = note & " " & " " &nt& " "&nt1
FrmDor1.TextBox4.Value = note & " " & " " & nt & " " &nt1
'THIS is my problem line
Sheets("Sheet1").Cells(N, 31) = Sheets("Sheet1").Cells_
(N, 11) - t - t2
End If

End Sub

Thanks for even looking at this. Any help will be appreciated.
CAA


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to

creating financial statements


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Type mismatch? string 2 a long??


Thanks for the help.

t = clng("0" & Trim(TextBox4.Value)) 'pack left
t2 = clng("0" & trim(TextBox5.Value)) 'pack right

seemd to tell me there was no object reference, so i sacked it off and
went for the just the CLng option, I assume it means change to long?
This didn't really work either, so instead i put in On error resume
next for both the lines, which worked out OK.
I think it's because there is no value i one of the textboxes, maybe i
should of wrote some code to handle that criterea, but it works now so
maybe not!

Thanks again.
CAA


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Type mismatch... George[_4_] Excel Discussion (Misc queries) 7 December 19th 07 12:20 PM
Type Mismatch [email protected] Excel Worksheet Functions 1 May 16th 07 03:29 PM
Type Mismatch Error David Excel Discussion (Misc queries) 2 December 11th 05 04:46 PM
type mismatch--how to fix rroach Excel Discussion (Misc queries) 2 July 14th 05 06:23 PM


All times are GMT +1. The time now is 04:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"