List Box Current Record

seeker63a

Registered User.
Local time
Today, 05:42
Joined
Mar 30, 2014
Messages
16
I have a list box that my client goes through with vbKeyDown and vbKeyUp. When he finds the correct record he wants to do vbKeyReturn and capture the checktype code and description and have them placed in a check which is another form that is open. The following code does not work but gives an idea as to what I need:

Private Sub List3_KeyDown(KeyCode as integer, Shift as Integer)
If KeyCode = vbKeyReturn Then
Forms!frmChecks![TRA{CODING =
Me.CurrentRecord.Column(1)
Forms!frmChecks![TRA:CODEDESC] =
Me.CurrentRecord.column(2)
DoCmd.Close adForm, "frmCheckType", acSaveNo
KeyCode = 0
End If

Thanks for the wisdom
 
I don't understand the Schema for this? However if you bind the controls on the destination form to the listbox, then you could adapt this code and make it work.
If Me.List0.ItemsSelected.Count = 0 Then
MsgBox "You must select at least 1 Item"
Exit Sub
End If

If KeyCode = vbKeyReturn Then

Dim strCodedesc As String
Dim strCoding As String
Dim varItem As Variant
For Each varItem In List0.ItemsSelected

strCoding = Me.List0.Column(2, varItem) & ";"
strCodedesc = Me.List0.Column(3, varItem) & ";"

Next varItem

If strCodedesc > "" Then
strCodedesc = Left(strCodedesc, Len(strCodedesc) - 1)
End If

If strCoding > "" Then
strCoding = Left(strCoding, Len(strCoding) - 1)
End If
End If

[Forms]![frmChecks]![Coding] = strCoding
[Forms]![frmChecks]![Codedesc] = strCodedesc
Forms!frmChecks.Dirty = False

HTH
 
I have yet to test but on initial run all looks good thanks. I am going to add if keycode = vbKeyUp & List3.ItemsSelected.Item(0) then
txtSearchCode.setfocus
end if

to see if that works as well. thanks for the push in the right direction.
 

Users who are viewing this thread

Back
Top Bottom