data type mis match error

  • Thread starter Thread starter dannie
  • Start date Start date
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?
 
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).
 
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
 
Back
Top