PC Review


Reply
Thread Tools Rate Thread

data type mis match error

 
 
dannie
Guest
Posts: n/a
 
      12th Mar 2010
I am getting a Compile error: Type-declaration character does not match
declared data type


Private Sub optMH1_Click()
Call SelectMHform(1)
End Sub

Sub SelectMHform(a As Integer)
With Forms("BaseForm")
.optMH& a&.value = 1
.txtPicture.value = "MH" + Str(a)
.cmbBoxMaterial.value = ""
.txtBoxLength.value = ""
End With
End Sub

I tried some other things too but I am still getting an error due to .optMH&
a&.value = 1 How do I use a variable in this situation?
 
Reply With Quote
 
 
 
 
Stuart McCall
Guest
Posts: n/a
 
      12th Mar 2010
"dannie" <(E-Mail Removed)> wrote in message
news:C67706AF-ADBB-4F0F-90D3-(E-Mail Removed)...
>I am getting a Compile error: Type-declaration character does not match
> declared data type
>
>
> Private Sub optMH1_Click()
> Call SelectMHform(1)
> End Sub
>
> Sub SelectMHform(a As Integer)
> With Forms("BaseForm")
> .optMH& a&.value = 1
> .txtPicture.value = "MH" + Str(a)
> .cmbBoxMaterial.value = ""
> .txtBoxLength.value = ""
> End With
> End Sub
>
> I tried some other things too but I am still getting an error due to
> .optMH&
> a&.value = 1 How do I use a variable in this situation?


Ampersand (&) is the type declaration character for a Long data type, not an
integer. There really is no need to use type declaration characters in VBA
(except in rare circumstances when calling a routine in a DLL). Dim(ension)
your variables instead.

a&.value will never work, because you're using object syntax, and an object
can't be a Long (it's an Object).


 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      12th Mar 2010
On Thu, 11 Mar 2010 16:28:01 -0800, dannie <(E-Mail Removed)>
wrote:

>I am getting a Compile error: Type-declaration character does not match
>declared data type
>
>
>Private Sub optMH1_Click()
>Call SelectMHform(1)
>End Sub
>
>Sub SelectMHform(a As Integer)
>With Forms("BaseForm")
> .optMH& a&.value = 1
> .txtPicture.value = "MH" + Str(a)
> .cmbBoxMaterial.value = ""
> .txtBoxLength.value = ""
>End With
>End Sub
>
>I tried some other things too but I am still getting an error due to .optMH&
>a&.value = 1 How do I use a variable in this situation?


If you're trying to set the value of .optMH1 or .optMH2 depending on what
you're passing to the variable a, you can't do it that way. Try

..Controls("optMH" & a).value = 1

--

John W. Vinson [MVP]
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF AND MATCH data type issue EZ Microsoft Excel Worksheet Functions 2 18th Jun 2009 05:35 PM
Do the data type have to match from one table to another =?Utf-8?B?bWF1cmE=?= Microsoft Access Database Table Design 1 31st Jan 2007 10:39 PM
Type mis-match error =?Utf-8?B?TWFyY290dGUgQQ==?= Microsoft Excel Programming 2 31st Mar 2005 02:17 AM
match data type sg Microsoft Access Form Coding 2 6th Dec 2004 08:22 PM
Pass Thru Query - Key Field Data Type Miss-Match Ross Microsoft Access VBA Modules 0 8th Mar 2004 03:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:29 AM.