L
lorirobn
Hi All,
I have a listbox on a main form. When user double-clicks an item in
the list box, I move the selected values to a subform at the bottom of
the form. List box is not multiselect, and subform is continuous form.
This is a work-in-progress, but seems to be working ok.
On my subform I have a sequence number field. When user selects from
the listbox, and the values are moved to the subform, I need to
calculate the sequence number for this new record based on values in
its table. (The table is one of the tables in the record source query
for the subform). I have set up an SQL string to do this, but not sure
how to use it. My question is: how can I use SQL to reference a table
within my List Box double-click event logic?
My List Box double-click event is:
Dim ctl As Control
Dim itm As Variant
Set ctl = Me![lstFurnListItems]
Me.fsubFurniture.SetFocus
DoCmd.GoToRecord , , acNewRec
For Each itm In ctl.ItemsSelected
If Not IsNull(itm) Then
Me!fsubFurniture!RoomID = txtRoomID.Value
Me!fsubFurniture!ItemID = ctl.Column(0, itm)
End If
Next
I want to have SQL something like:
Dim strSql As String
strSql = "SELECT tblRoomItems.SeqNo " _
& " FROM tblRoomItems " _
& " WHERE (((tblRoomItems.RoomID) = '" & txtRoomID.Value & "')"
_
& " AND ((tblRoomItems.ItemID) = " & ctl.Column(0, itm) & "));"
I tried doing something like the following, but it didn't work:
Dim recset As Recordset
Set recset = CurrentDb.OpenRecordset(strSql)
Me!fsubFurniture!SeqNo = tblRoomItems.SeqNo + 1
Appreciate any suggestions!
Thanks,
Lori
I have a listbox on a main form. When user double-clicks an item in
the list box, I move the selected values to a subform at the bottom of
the form. List box is not multiselect, and subform is continuous form.
This is a work-in-progress, but seems to be working ok.
On my subform I have a sequence number field. When user selects from
the listbox, and the values are moved to the subform, I need to
calculate the sequence number for this new record based on values in
its table. (The table is one of the tables in the record source query
for the subform). I have set up an SQL string to do this, but not sure
how to use it. My question is: how can I use SQL to reference a table
within my List Box double-click event logic?
My List Box double-click event is:
Dim ctl As Control
Dim itm As Variant
Set ctl = Me![lstFurnListItems]
Me.fsubFurniture.SetFocus
DoCmd.GoToRecord , , acNewRec
For Each itm In ctl.ItemsSelected
If Not IsNull(itm) Then
Me!fsubFurniture!RoomID = txtRoomID.Value
Me!fsubFurniture!ItemID = ctl.Column(0, itm)
End If
Next
I want to have SQL something like:
Dim strSql As String
strSql = "SELECT tblRoomItems.SeqNo " _
& " FROM tblRoomItems " _
& " WHERE (((tblRoomItems.RoomID) = '" & txtRoomID.Value & "')"
_
& " AND ((tblRoomItems.ItemID) = " & ctl.Column(0, itm) & "));"
I tried doing something like the following, but it didn't work:
Dim recset As Recordset
Set recset = CurrentDb.OpenRecordset(strSql)
Me!fsubFurniture!SeqNo = tblRoomItems.SeqNo + 1
Appreciate any suggestions!
Thanks,
Lori