ListIndex Incorrect

D

DS

I'm Running this code and I get an Error 7777
saying that I used the ListIndex incorrectly. After I click end It
shows the Printer attached in the combo box. What am I doing wrong?
Thanks
DS


Private Sub Form_Load()
'Add each printer installed to the combo box list
Dim X As Printer
Dim rtn As Long
Dim Driver As String
Dim I As Integer

m_ESCNFlg = False

For Each X In Printers
rtn = GetPrnDriverName(X.DeviceName, Driver)
If rtn <> 0 Then
Driver = ""
End If

If InStr(Driver, "EPSON TM") <> 0 Or _
InStr(Driver, "EPSON RP") <> 0 Or _
InStr(Driver, "EPSON EU") <> 0 Or _
InStr(Driver, "EPSON BA") <> 0 Then
CmbPrn.AddItem (X.DeviceName)
End If
Next

If CmbPrn.ListCount <> 0 Then
CmbPrn.ListIndex = 0
End If

rtn = GetPrnDriverName(CmbPrn.Text, Driver)
If rtn <> 0 Then
Driver = ""
End If

If Driver = DRV_NAME_TMH6000II_ENDORSE Then
ButnESCNEnable.Enabled = True
Else
ButnESCNEnable.Enabled = False
End If
End Sub
 
M

Marshall Barton

DS said:
I'm Running this code and I get an Error 7777
saying that I used the ListIndex incorrectly. After I click end It
shows the Printer attached in the combo box. What am I doing wrong?

Private Sub Form_Load() [snip]
If CmbPrn.ListCount <> 0 Then
CmbPrn.ListIndex = 0
[snip]


You can not set the ListIndex property unless the combo/list
box has the focus. I'm not sure, but the Load event might
be too early to be setting the focus. Regardless of whether
it is or not, you should be using the ItemData property
instead:
Me.CmbPrn = Me.CmbPrn.ItemData(0)
 
G

George Nicholson

FWIW....

AFAIK, for Access textboxes, ListIndex is read-only. VB listboxes it's
Read-write.

The Access Help entry start off saying it is Read-write but later it says
read-only. My experience leads me to believe that read-only is correct.

--
HTH,
George Nicholson

If used, remove Junk from return address.



Marshall Barton said:
DS said:
I'm Running this code and I get an Error 7777
saying that I used the ListIndex incorrectly. After I click end It
shows the Printer attached in the combo box. What am I doing wrong?

Private Sub Form_Load() [snip]
If CmbPrn.ListCount <> 0 Then
CmbPrn.ListIndex = 0
[snip]


You can not set the ListIndex property unless the combo/list
box has the focus. I'm not sure, but the Load event might
be too early to be setting the focus. Regardless of whether
it is or not, you should be using the ItemData property
instead:
Me.CmbPrn = Me.CmbPrn.ItemData(0)
 
D

DS

Marshall said:
DS wrote:

I'm Running this code and I get an Error 7777
saying that I used the ListIndex incorrectly. After I click end It
shows the Printer attached in the combo box. What am I doing wrong?

Private Sub Form_Load()
[snip]

If CmbPrn.ListCount <> 0 Then
CmbPrn.ListIndex = 0

[snip]


You can not set the ListIndex property unless the combo/list
box has the focus. I'm not sure, but the Load event might
be too early to be setting the focus. Regardless of whether
it is or not, you should be using the ItemData property
instead:
Me.CmbPrn = Me.CmbPrn.ItemData(0)
Thanks, I'll give it a try.
DS
 
D

DS

Marshall said:
DS wrote:

I'm Running this code and I get an Error 7777
saying that I used the ListIndex incorrectly. After I click end It
shows the Printer attached in the combo box. What am I doing wrong?

Private Sub Form_Load()
[snip]

If CmbPrn.ListCount <> 0 Then
CmbPrn.ListIndex = 0

[snip]


You can not set the ListIndex property unless the combo/list
box has the focus. I'm not sure, but the Load event might
be too early to be setting the focus. Regardless of whether
it is or not, you should be using the ItemData property
instead:
Me.CmbPrn = Me.CmbPrn.ItemData(0)
Thanks Marshall that worked.
DS
 
S

Stephen Lebans

FWIW the Help file is incorrect.
You can write to the property providing the control has the focus.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


George Nicholson said:
FWIW....

AFAIK, for Access textboxes, ListIndex is read-only. VB listboxes it's
Read-write.

The Access Help entry start off saying it is Read-write but later it says
read-only. My experience leads me to believe that read-only is correct.

--
HTH,
George Nicholson

If used, remove Junk from return address.



Marshall Barton said:
DS said:
I'm Running this code and I get an Error 7777
saying that I used the ListIndex incorrectly. After I click end It
shows the Printer attached in the combo box. What am I doing wrong?

Private Sub Form_Load() [snip]
If CmbPrn.ListCount <> 0 Then
CmbPrn.ListIndex = 0
[snip]


You can not set the ListIndex property unless the combo/list
box has the focus. I'm not sure, but the Load event might
be too early to be setting the focus. Regardless of whether
it is or not, you should be using the ItemData property
instead:
Me.CmbPrn = Me.CmbPrn.ItemData(0)
 

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

Similar Threads

Code Is Slow 3
Code Is Slow 6
Code Stopped Working 1
VB Code In VBA 8
(no subject) 0
type mismatch error in macro in excel 0
VB and VBA 0
Printing Extra Pages to PDF 1

Top