having a problem with a combobox

  • Thread starter Thread starter Zygoid
  • Start date Start date
Z

Zygoid

not sure what you mean Dave.
this is the code i have. perhaps it is the way it is created and save
as CLng.
I have tried different codes but none work. All the other comboboxes o
the form work fine,
but they all are alphabets. this is the only numeric. and the only on
with a problem.

on the initialize, it creates a new jobnumber in textbox1.
and fills a combobox with jobnumbers created in the past.
the form allows to create a new or open a past job.


Private Sub UserForm_Initialize()

Dim mydate As Date
Dim wb As Workbook
Dim rng As Range

Application.DisplayAlerts = False
Application.ScreenUpdating = False

Set wb = Workbooks.Open("f:\book2.xls")

With wb.Sheets("sheet1")
FName = Range("A65536").End(xlUp).Offset(1, 0).Row
Me.textbox1.Value = Format$(Date, "mmddyy") & FName
Me.textbox1.Value = CLng(Me.textbox1.Value)
End With

With wb.Sheets("sheet1")
Set rng = .Range(.Range("A2"), .Range("A2").End(xlDown))
End With
Me.combobox1.List = rng.Value
wb.Close False

end sub

if a new job or past job is changed. the user clicks the save button
this is how it is saved.

Private Sub cmdSave_Click()

Dim res As Variant
Dim SourceWB As Workbook
Dim SourceRng As Range
Dim DestCell As Range

Set SourceWB = Workbooks.Open("f:\book2.xls")
With SourceWB.Sheets("sheet1")
Set SourceRng = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))
res = Application.Match(CLng(textbox1.Value), SourceRng, 0)
If IsError(res) Then
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
Else
Set DestCell = SourceRng(res)
End If
With DestCell
.Offset(0, 0) = textbox1.Value
'alot more offsets but this is the referenced.

end sub


I am not sure if the way the number is saved
 
My suggestion was more routine.

I went into design mode, rightclicked the combobox and selected properties.

I scrolled down to the .matchentry property.

The only way I could have it not complete was if I had .matchentry set to
"2 - fmMatchEntryNone"

I just tried again. It didn't complete for plain old numbers. I could have
sworn it completed when I tried it earlier.

But maybe you could add the values as strings:

Dim rng As Range
Dim myCell As Range

With wb.Sheets("sheet1")

With Me
Set rng = .Range(.Range("A2"), .Range("A2").End(xlDown))
End With

For Each myCell In rng.Cells
Me.ComboBox1.AddItem myCell.Text
Next myCell

End With

It uses the same format as what you see in the cells.
 

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

Back
Top