I have a unbound form (called fBulkRequest) on which I'd like users to makes some selections and then click a button which then adds records to a table called tRequestDetail. I'm having trouble figuring out the syntax to do this:
At some point, I need to put error checking into this, but I'll like to figure that out after this. I've had a read of a few things and have assumed that the INSERT INTO SQL function is what's needed, but I'm confused about how to pass the various values in AND 1) for each item in the lstLocation cycle though and add a new record as well as 2) create one new record in another table and pull that value back.... This is my first attempt on notepad, but it's a bit late and I'm dog tired for me to risk playing with the form right now, but comments as to if I'm in the right direction or barking up the wrong tree would be greatly appreciated:
- lstRequest (listbox), bound column (1) is IDRequest. I want to pass the selected item from lstRequest (only 1 selection can be made) into tRequestDetails.FIDRequest.
- cboSoftwareItem (combobox), bound column (1) is IDVersion. I want to pass the selected item from cboSoftwareItem into tRequestDetails.FIDVersion
- txtConfiguration (txtbox unbound). I want to create a new record in tConfigInfo (IDConfigInfo, Configuration) and pass THAT IDConfigInfo into tRequestDetails.FIDConfigInfo.
At some point, I need to put error checking into this, but I'll like to figure that out after this. I've had a read of a few things and have assumed that the INSERT INTO SQL function is what's needed, but I'm confused about how to pass the various values in AND 1) for each item in the lstLocation cycle though and add a new record as well as 2) create one new record in another table and pull that value back.... This is my first attempt on notepad, but it's a bit late and I'm dog tired for me to risk playing with the form right now, but comments as to if I'm in the right direction or barking up the wrong tree would be greatly appreciated:
Code:
Private Sub BulkAdd_Click()
Dim NewCI as String
Dim intX As Integer
Dim strADDSTUFF as String
NewCI = "INSERT INTO tConfigInfo (Configuration) SELECT txtConfiguration FROM fBulkRequest;"
[COLOR="SeaGreen"]How to return the new IDCOnfigInfo to then use below?[/COLOR]
For intX = 0 To Me.lstLocation.ListCount - 1
Me.lstLocation.Selected(intX) = True
strADDSTUFF = "INSERT INTO tRequestDetail (FIDRequest, FIDVersion, FIDLocation, FIDConfigInfo)"
& " SELECT " & Me.lstRequest.Selected.Column(0) & ", "
& " SELECT " & Me.cboSoftwareItem.Column(0) & ", "
& " SELECT " & Me.lstLocation.Column(0) ", "
& " SELECT ???????;" [COLOR="Seagreen"]'how to return the IDConfigInfo from above[/COLOR]
Next intX
End Sub