So you know my Main form is now named Vehicleand
EquipMain (added an i) and the job subform is named subRepairMaintJobs.
Did you also rename the sub-form control (not the subform)???
I modified your code.
Is this what you want?
Code:
Private Sub lstUnusedParts_DblClick(Cancel As Integer)
Dim sSQL As String
Dim Msg As String, Ans As Variant
Dim vJobNum As Variant
'get job number
' because the job number is on the subform "subRepairMaintJobs", you should
'be able to refer to it using "Me.JobNumber"
' vJobNum = Nz(Forms![VehicleandEquipMain]![subRepairMaintJobs].Forms![JobNumber], 0)
vJobNum = Nz(Me.JobNumber, 0)
'for debugging, show the value of vJobNum
' MsgBox "Job # = " & vJobNum
If vJobNum = 0 Then 'no job # selected
MsgBox "You must create a job before adding any parts to it", vbOKOnly
Else
Msg = "Are you sure you want to add this part: " & Me.lstUnusedParts.Column(1) & " to your Job?"
' Msg = "Are you sure you want to add this part to your Job?"
Ans = MsgBox(Msg, vbYesNo)
Select Case Ans
Case vbYes
sSQL = "Update Parts Set[JobNumber]=" & vJobNum
'the bound column is the default, so you don't have to type ".Column(0)
sSQL = sSQL & " WHERE [CJBPartNumber] = " & Me.lstUnusedParts
'set a breakpoint and see what the string look like
'open the immediate window
Debug.Print sSQL
CurrentDb.Execute sSQL, dbFailOnError
Case vbNo
'do nothing
End Select
End If
End Sub
my situation is slightly different as I don't necessarily need to add a new record to the table based on my listbox, but simply just update or populate one field in the table of each record that was selected in the list box (the JobNumber)
since that field would be empty as the part was added before any job was made to add it to it .
What???
I really don't understand what you are doing.
I would expect a "customer" table, a "jobs" table with a customer_FK field, a "JobsParts" junction table with Jobs_FK and Parts_FK fields.
Table: Customers
------------
CustID (PK)
'other fields
Table: Jobs
------------
JobID (PK)
CustID_FK
'other fields
Table: AllParts
-----------
AllPartsID (PK)
'other fields
Table: JobsParts
----------------
JobsPartsID (PK)
JobID_FK
AllPartsID_FK
'other fields
It doesn't really matter if I understand or not, as long as you are getting the results you want.
--------------
You might want to change the text in your label to remove the "(s)" after Parts in the label that begins with "Select the Part(s)..."
BTW, you could use a multi-select list box, it just takes a little more code to add the parts since you have to have a loop to get the selected items.