PDA

View Full Version : COMBOBOX Value Recall



erixon019
08-09-2018, 08:50 PM
I am a newbie on Excel VBA programming, please bear with me.
I tried to look at the forum but I cannot find the right answer to my problem.

My problem is i cannot recall the combobox value stored on Sheet1, when i click the edit button to recall all the data inputed on every textbox.
Data inputed on the textboxes were saved on a specific sheet (Sheet1). There are only 2 choice/values on the combobox.
If Sheet1.Range("D8").Value is 1.17 there is no problem.
If Sheet1.Range("D8").Value is 0.8 then it returns an error, Run-time error 380 "Could not set the Value property. Invalid property value.

MoldCapThickness.Clear
With MoldCapThickness
.AddItem "1.17"
.AddItem "0.80"
End With

Private Sub Edit1_Click()


SolderBallPitch.Value = Sheet1.Range("D4").Value
MaxWireLength.Value = Sheet1.Range("D7").Value
'MoldCapThickness is a combobox
MoldCapThickness = Sheet1.Range("D8").Value


End Sub

Thanks for the help

OBP
08-10-2018, 07:24 AM
Although this is an Excel problem on an Access Forum, do you get the error message when the code running is
.AddItem "0.80"
or
MoldCapThickness = Sheet1.Range("D8").Value

erixon019
08-14-2018, 12:25 AM
Thank you for the reply, and apology for the wrong post on the Access forum.

I was able to find an answer to my problem, but actually i dont fully understand the solution.
The error occured on "MoldCapThickness = Sheet1.Range("D8").Value". with Run-time error 380 "Could not set the Value property. Invalid property value.

One of the solution for this error is to declare a variable that can accept numbers and string, so that the value will be accepted.
I tried to declare a variable with variant data type. And then my problem was solved.
I tried other data type and only variant was working and i dont understand why double or long is not working.

Below are the working codes.

Dim iMCT As Variant

iMCT = Sheet1.Range("D8").Value
MoldCapThickness.Value = iMCT

OBP
08-14-2018, 12:44 AM
The "Variant" type is basically a holding variable that will accept whatever is entered and is decided on the actual entry.
Whereas Double and Long are both "Numeric" only variables.
You could try a String variable as that also basicaly accepts any input.
That was why I asked the question, you may be trying to assign a string value, ie used inverted commas rather than a numeric value, however that usually provokes a Type Mismatch error.
I am glad you have got it working.

erixon019
08-15-2018, 07:02 PM
Thank you for the time and for the explanation.