R
Rachel
Hi,
Please can you help. I have added a listbox to a subform to enable the
user to select more than one option, I then want a table to be updated
with this infomation via a command button. ie this could mean
inserting several rows if more than one item is selected.
I have a form with the following controls:
A text box called txt_Case_ID
A listbox called lst_Diag (row source is from another table called
tbl_Medical)
There is no record source set for this form.
I have a table called tbl_Multi (to store the multiple entries) with
the following fields:
Multi_ID (this is the PK) (this is an auto number)
Medical_ID (this is a PK in another table - tbl_Medical) (I want this
to be updated by lst_Diag)
Case_ID (this is a PK in another table) (I want this to be updated by
txt_Case_ID)
I have added the following code to a command button:
Private Sub Command6_Click()
Dim strSQL As String
Dim varItem As Variant
For Each varItem In Me.lst_Diag.ItemsSelected
strSQL = "UPDATE [tbl_Multi] SET Case_ID = '" &
Replace(Me.txt_Case_ID, "'", "''") & "' WHERE Medical_ID = " &
Me.lst_Diag.ItemData(varItem)
CurrentDb.Execute strSQL
Next
Me.lst_Diag.Requery
End Sub
However I keep getting this error "Runtime error 91, with block
variable not set"
I have tried everything to get this to work but I keep failing.
Can anyone help me please?
Rachel
Please can you help. I have added a listbox to a subform to enable the
user to select more than one option, I then want a table to be updated
with this infomation via a command button. ie this could mean
inserting several rows if more than one item is selected.
I have a form with the following controls:
A text box called txt_Case_ID
A listbox called lst_Diag (row source is from another table called
tbl_Medical)
There is no record source set for this form.
I have a table called tbl_Multi (to store the multiple entries) with
the following fields:
Multi_ID (this is the PK) (this is an auto number)
Medical_ID (this is a PK in another table - tbl_Medical) (I want this
to be updated by lst_Diag)
Case_ID (this is a PK in another table) (I want this to be updated by
txt_Case_ID)
I have added the following code to a command button:
Private Sub Command6_Click()
Dim strSQL As String
Dim varItem As Variant
For Each varItem In Me.lst_Diag.ItemsSelected
strSQL = "UPDATE [tbl_Multi] SET Case_ID = '" &
Replace(Me.txt_Case_ID, "'", "''") & "' WHERE Medical_ID = " &
Me.lst_Diag.ItemData(varItem)
CurrentDb.Execute strSQL
Next
Me.lst_Diag.Requery
End Sub
However I keep getting this error "Runtime error 91, with block
variable not set"
I have tried everything to get this to work but I keep failing.
Can anyone help me please?
Rachel