Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default TYPE MISMATCH

I am getting a runtime error of "Type Mismatch" and can not figure out
why:

I declare the following:

Public ctlFormControl, ctlFormControl_2 As Controls

These Control variables are then used in the following procedure which
fills in item controls on a form called "frmCreateOrder" by taking text
from "frmNewOrder." This is done by looping through the controls on
the given form, using the TabIndex of the controls on the form.

Sub CreateOrderItems()
For i = 4 To 12 Step 2
For Each ctlFormControl In frmNewOrder.Controls
If ctlFormControl.TabIndex = i Then
strCtrltext = ctlFormControl.Text
For j = 9 To 33 Step 6


TYPE MISMATCH OCCURS IN THE FOLLOWING BLOCK:

For Each ctlFormControl_2 In
frmCreateOrder.Controls
If ctlFormControl_2.TabIndex = i Then
ctlFormControl_2.Caption = strCtrltext
End If
Next ctlFormControl_2


Next j
End If
Next ctlFormControl
Next i

It appears that VBA is having a problem with ctlFormControl_2. The
puzzling thing is that ctlFormControl is declared the same way, used in
the same way, and works.

Any Suggestions as to what the problem is?

Thanks,
Brian

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default TYPE MISMATCH

Brian,

Your control declaration actually declared ctlFormControl as a variant,
which is why there was no error with that one. With ctlFormControl_2 you
want to declare it as a control - not plural:

Public ctlFormControl as Control, ctlFormControl_2 As Control

hth,

Doug

wrote in message
oups.com...
I am getting a runtime error of "Type Mismatch" and can not figure out
why:

I declare the following:

Public ctlFormControl, ctlFormControl_2 As Controls

These Control variables are then used in the following procedure which
fills in item controls on a form called "frmCreateOrder" by taking text
from "frmNewOrder." This is done by looping through the controls on
the given form, using the TabIndex of the controls on the form.

Sub CreateOrderItems()
For i = 4 To 12 Step 2
For Each ctlFormControl In frmNewOrder.Controls
If ctlFormControl.TabIndex = i Then
strCtrltext = ctlFormControl.Text
For j = 9 To 33 Step 6


TYPE MISMATCH OCCURS IN THE FOLLOWING BLOCK:

For Each ctlFormControl_2 In
frmCreateOrder.Controls
If ctlFormControl_2.TabIndex = i Then
ctlFormControl_2.Caption = strCtrltext
End If
Next ctlFormControl_2


Next j
End If
Next ctlFormControl
Next i

It appears that VBA is having a problem with ctlFormControl_2. The
puzzling thing is that ctlFormControl is declared the same way, used in
the same way, and works.

Any Suggestions as to what the problem is?

Thanks,
Brian



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default TYPE MISMATCH

ctlFormControl is of type variant, so you do not get the error.
ctlFormControl_2 is of type control (which I don't think will compile).
Change it to type variant and you should be off and running...

Check out this link on declaring variables...
http://www.cpearson.com/excel/variables.htm
--
HTH...

Jim Thomlinson


" wrote:

I am getting a runtime error of "Type Mismatch" and can not figure out
why:

I declare the following:

Public ctlFormControl, ctlFormControl_2 As Controls

These Control variables are then used in the following procedure which
fills in item controls on a form called "frmCreateOrder" by taking text
from "frmNewOrder." This is done by looping through the controls on
the given form, using the TabIndex of the controls on the form.

Sub CreateOrderItems()
For i = 4 To 12 Step 2
For Each ctlFormControl In frmNewOrder.Controls
If ctlFormControl.TabIndex = i Then
strCtrltext = ctlFormControl.Text
For j = 9 To 33 Step 6


TYPE MISMATCH OCCURS IN THE FOLLOWING BLOCK:

For Each ctlFormControl_2 In
frmCreateOrder.Controls
If ctlFormControl_2.TabIndex = i Then
ctlFormControl_2.Caption = strCtrltext
End If
Next ctlFormControl_2


Next j
End If
Next ctlFormControl
Next i

It appears that VBA is having a problem with ctlFormControl_2. The
puzzling thing is that ctlFormControl is declared the same way, used in
the same way, and works.

Any Suggestions as to what the problem is?

Thanks,
Brian


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default TYPE MISMATCH

Thanks Doug & Jim!

That makes a lot of sense and I think that problem is solved.

The big problem that I have now is that control objects, i.e.
ctlFormControl & ctlFormControl2, do not support the text or caption
proporties and I need to be able to get the text or cation out of the
selected control..........I can't see a way to do this. For example:

in this procedure I am looping through the controls on form
frmQueryResult, getting the tabindex for a given control on the form,
then finding the corresponding control on form frmCreateOrder. I want
to set the control value in frmCreateOrder to the value in the
frmQueryResult control.

Doesn't work...........

'fill in item availability controls on create order form
Sub CreateOrderItemAvail()
For i = 6 To 22 Step 4
For Each ctlFormControl In frmQueryResult.Controls
If ctlFormControl.TabIndex = i Then
strCtrltext = ctlFormControl.Caption
For j = 11 To 35 Step 6
For Each ctlFormControl_2 In
frmCreateOrder.Controls
If ctlFormControl_2.TabIndex = j Then
ctlFormControl_2.Caption = strCtrltext
End If
Next ctlFormControl_2
Next j
End If
Next ctlFormControl
Next i
End Sub

Brian

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default TYPE MISMATCH

I'm in a hurry, so don't have time to name all your variables back to the
beginning. Take a look at this though, I think it will give some help.
Don't see a need for global variables. TabIndex starts at 0, not 1, which I
realized easily since my forms only had one control each.

Anyways, hope this gives some help:

Option Explicit

Sub CreateOrderItemAvail()

Dim ctlFormControl, ctlFormControl_2 As MSForms.Control
Dim i As Long, j As Long
Dim strCtrltext As String

For i = 0 To 22 Step 4
For Each ctlFormControl In UserForm1.Controls
If ctlFormControl.TabIndex = i Then
strCtrltext = ctlFormControl.Caption
For j = 0 To 35 Step 6
For Each ctlFormControl_2 In UserForm2.Controls
If ctlFormControl_2.TabIndex = j Then
ctlFormControl_2.Caption = strCtrltext
End If
Next ctlFormControl_2
Next j
End If
Next ctlFormControl
Next i
UserForm1.Show
UserForm2.Show
MsgBox "Is this what you want?"
Unload UserForm1
Unload UserForm2

End Sub

Doug


wrote in message
oups.com...
Thanks Doug & Jim!

That makes a lot of sense and I think that problem is solved.

The big problem that I have now is that control objects, i.e.
ctlFormControl & ctlFormControl2, do not support the text or caption
proporties and I need to be able to get the text or cation out of the
selected control..........I can't see a way to do this. For example:

in this procedure I am looping through the controls on form
frmQueryResult, getting the tabindex for a given control on the form,
then finding the corresponding control on form frmCreateOrder. I want
to set the control value in frmCreateOrder to the value in the
frmQueryResult control.

Doesn't work...........

'fill in item availability controls on create order form
Sub CreateOrderItemAvail()
For i = 6 To 22 Step 4
For Each ctlFormControl In frmQueryResult.Controls
If ctlFormControl.TabIndex = i Then
strCtrltext = ctlFormControl.Caption
For j = 11 To 35 Step 6
For Each ctlFormControl_2 In
frmCreateOrder.Controls
If ctlFormControl_2.TabIndex = j Then
ctlFormControl_2.Caption = strCtrltext
End If
Next ctlFormControl_2
Next j
End If
Next ctlFormControl
Next i
End Sub

Brian



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 using rnge as Range with Type 8 Input Box STEVE BELL Excel Programming 11 December 3rd 05 05:02 AM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
type mismatch--how to fix rroach Excel Discussion (Misc queries) 2 July 14th 05 06:23 PM
13 type mismatch help Mike K Excel Programming 2 June 23rd 05 02:51 AM
Type mismatch Steve Garman Excel Programming 0 February 5th 04 07:39 AM


All times are GMT +1. The time now is 02:06 AM.

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

About Us

"It's about Microsoft Excel"