Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie question: Type mismatch error

Status
Not open for further replies.

RSX02

Programmer
May 15, 2003
467
CA
Hi!
I'm pretty new with VBA. This is my code and I get a type mismatch error where I put ***. The only thing I want is to set my variable "BGTaskName" with the value "mods_commercialinvoice". Any idea what's wrong with my code?

Thanks in advance
Sub Main()
If ThisForm.Components("shipcountry") = "USA" Then
***ThisForm.Variables("BGTaskName") = "mods_commercialinvoice"

Else
If ThisForm.Components(&quot;shipcountry&quot;) <> &quot;USA&quot; And ThisForm.Components(&quot;&quot;) <> &quot;Canada&quot; Then
ThisForm.Variables(&quot;BGTaskName&quot;) = &quot;mods_ExportDeclaration&quot;
End If
End If
End Sub
 
Code:
Sub Main()
[blue]
Code:
Dim BGTaskName As String
[/color]
Code:
    If ThisForm.Components(&quot;shipcountry&quot;) = &quot;USA&quot; Then
      BGTaskName = &quot;mods_commercialinvoice&quot;
    Else
      If ThisForm.Components(&quot;shipcountry&quot;) <> &quot;USA&quot; And ThisForm.Components(&quot;
[blue]
Code:
shipcountry
[/color]
Code:
&quot;) <> &quot;Canada&quot; Then
        BGTaskName = &quot;mods_ExportDeclaration&quot;
      End If
    End If
End Sub
 
Zathras
Thanks for the &quot;shipcountry&quot; I forgot it.
But for the dim BGTaskName as string, it's a variable that it's in my application. So the BGTaskName variable is already declared somewhere else.
Do you have any other idea?
 
When you declare BGTaskName, make it global. I.e., Put this before the first Sub or Function declaration in any code module:
[blue]
Code:
Option Explicit
Public BGTaskName As String
[green]
Code:
' Other global declarations...
[/color]
Code:
Sub SomethingOrOther( )
   xxx 
   xxx
End Sub
[green]
Code:
' Etc.
[/color][/color]


 
Zathras.
This variable is declare in my application which means that it's not declared in VBA. In my application I use form. These form use components and variables. For the component I know that I can do
Thisform.Components(&quot;Name of the component&quot;) = &quot;Value&quot;
But it's seems that I can't do that with the variables. I tried to not put the &quot;Thisform.Variables&quot; before the name of the variable but it's doesn't work either.
Thanks in advance again.
 
Please describe exactly how you are declaring your variable. I do not understand how you can ...declare in my application... and at the same time ...it's not declared in VBA...

Perhaps you could start by saying what the application is. Word? Excel? Access? Outlook? PowerPoint?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top