data type mis match error

D

dannie

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?
 
S

Stuart McCall

dannie said:
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).
 
J

John W. Vinson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top