PDA

View Full Version : کاربالیست باکس



amirkazem
یک شنبه 01 بهمن 1391, 18:50 عصر
دوستان سلام
تگه براتون مقدورهستش، کمی ازکارکردن بالیست باکس دراکسس مطلب بنویسید.
مطالبی درموردمثلاً:
1:مشاهده نتیجه کوئری درلیست باکس توی فرم
2.انتخاب یک رکوردازلیست باکس وویرایش آن درفرم دیگر
3وهرمطلب که فکرمی کنیدبرای دوستان درمبحث لیست باکس مفیدهستش رالطف کنید.

قبلاًازهمکاری شماصمیمانه تشکرمی کنم.
:بوس::بوس::بوس:

bitasoft.ir
پنج شنبه 26 بهمن 1391, 22:41 عصر
سلام
این هم چند تا مثال



With Me.lstbox
Me.lstbox.ColumnCount = 2
Me.lstbox.ColumnWidths = "60;60"
.AddItem
.List(0, 0) = Company_ID
.List(0, 1) = Company_name
end with






Sub AddLogRecord()

Dim historyWks As Worksheet
Dim inputWks As Worksheet

Dim nextRow As Long
Dim oCol As Long

Dim myCopy As Range
Dim myTest As Range

Dim LB As MSForms.ListBox
Dim lCount As Long

Set inputWks = Worksheets("DataEntry")
Set historyWks = Worksheets("VolunteerList")

Set LB = inputWks.OLEObjects("LB_Days").Object
'cells to copy from Input sheet
Set myCopy = inputWks.Range("VolInfo")

oCol = 3 'starting column where copied data is pasted

With historyWks
nextRow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
End With

With inputWks
If Application.CountA(myCopy) <> myCopy.Cells.Count Then
MsgBox "Please fill in all the cells!"
Exit Sub
End If
End With

With historyWks
With .Cells(nextRow, "A")
.Value = Now
.NumberFormat = "mm/dd/yyyy hh:mm:ss"
End With
.Cells(nextRow, "B").Value = Application.UserName
myCopy.Copy
.Cells(nextRow, oCol).PasteSpecial Paste:=xlPasteValues, Transpose:=True
Application.CutCopyMode = False
End With

oCol = oCol + myCopy.Cells.Count

'------------
'get list data

With LB
For lCount = 0 To .ListCount - 1
If .Selected(lCount) Then
historyWks.Cells(nextRow, oCol).Value = .List(lCount)
oCol = oCol + 1
End If
Next
End With
'------------

'clear input cells
With myCopy
.Cells.ClearContents
.Cells(1).Select
End With

'clear Days list
DayListClear

End Sub

'==================================

Sub DayListClear()

Dim ws As Worksheet
Dim LB As MSForms.ListBox
Dim lCount As Long

Set ws = ActiveSheet
Set LB = ws.OLEObjects("LB_Days").Object

With LB
For lCount = 0 To .ListCount - 1
.Selected(lCount) = False
Next
End With

End Sub





txtS.Value = lstS.ItemsSelected.Item(0).Value





Dim result as String, i as Integer

For i = 0 to lstS.ListCount - 1
If lstS.Selected(i) result = result & lstS.List(i, columnindex) & ", "
Next i

txtS.Value = result