B
BillD
I have an Access Database with a Table that includes Constituents Names and
Addresses. I use an unbound Combo to bring up a dropdown list of
Constituents. When I select a record from the list the form shows the info
for the new Constituent(person) selected.
I have another Unbound Combo on the form that I want to use to change the
address fields and a couple other fields for the person to the new address
selected.
Currently the dropdown list in the "cmb_addr_change" lists the address from
the Table. When I select an address from the list the fields for the address
are changed to the address fields selected. This works good. The PROBLEM I am
having is when I select an address from the drop-down list there is a box
that comes up before the fields for the record are changed. The box states
"Are you sure you want to update this record?" Yes or No. If I select Yes the
address fields are changed to the address selected and the box closes. If I
select No then a Run-Time error '2501' appears. Run SQL action was canceled.
How do I correct this? If I select No I just want the box to close and not
make the address changes to the record. Here is the code I have in the After
Update Event Procedure.
Private Sub cmb_Addr_change_AfterUpdate()
Dim SQL_Text As String
SQL_Text = "UPDATE VoterInformationTable "
SQL_Text = SQL_Text & " SET [PED] = " & Me.cmb_Addr_change.Column(1) & ","
SQL_Text = SQL_Text & " [Poll] = " & Me.cmb_Addr_change.Column(2) & ","
SQL_Text = SQL_Text & " [St#] = " & Me.cmb_Addr_change.Column(3) & ","
SQL_Text = SQL_Text & " [AddressInfoId] = " &
Me.cmb_Addr_change.Column(0) & ","
SQL_Text = SQL_Text & " [StSuffix] = '" & Me.cmb_Addr_change.Column(4) &
" ',"
SQL_Text = SQL_Text & " [Street] = '" & Me.cmb_Addr_change.Column(5) & "
',"
SQL_Text = SQL_Text & " [Street Type] = '" &
Me.cmb_Addr_change.Column(6) & " ',"
SQL_Text = SQL_Text & " [StreetDir] = '" & Me.cmb_Addr_change.Column(7)
& " ',"
SQL_Text = SQL_Text & " [Apt#] = '" & Me.cmb_Addr_change.Column(8) & " ',"
SQL_Text = SQL_Text & " [City] = '" & Me.cmb_Addr_change.Column(9) & " ',"
SQL_Text = SQL_Text & " [Prov] = '" & Me.cmb_Addr_change.Column(10) & "
',"
SQL_Text = SQL_Text & " [Postal Code] = '" &
Me.cmb_Addr_change.Column(11) & " ' "
SQL_Text = SQL_Text & " WHERE [ID]= " & (Me.txtLbl)
DoCmd.RunSQL (SQL_Text)
SQL_Text = ""
MsgBox "Completed"
End Sub
Addresses. I use an unbound Combo to bring up a dropdown list of
Constituents. When I select a record from the list the form shows the info
for the new Constituent(person) selected.
I have another Unbound Combo on the form that I want to use to change the
address fields and a couple other fields for the person to the new address
selected.
Currently the dropdown list in the "cmb_addr_change" lists the address from
the Table. When I select an address from the list the fields for the address
are changed to the address fields selected. This works good. The PROBLEM I am
having is when I select an address from the drop-down list there is a box
that comes up before the fields for the record are changed. The box states
"Are you sure you want to update this record?" Yes or No. If I select Yes the
address fields are changed to the address selected and the box closes. If I
select No then a Run-Time error '2501' appears. Run SQL action was canceled.
How do I correct this? If I select No I just want the box to close and not
make the address changes to the record. Here is the code I have in the After
Update Event Procedure.
Private Sub cmb_Addr_change_AfterUpdate()
Dim SQL_Text As String
SQL_Text = "UPDATE VoterInformationTable "
SQL_Text = SQL_Text & " SET [PED] = " & Me.cmb_Addr_change.Column(1) & ","
SQL_Text = SQL_Text & " [Poll] = " & Me.cmb_Addr_change.Column(2) & ","
SQL_Text = SQL_Text & " [St#] = " & Me.cmb_Addr_change.Column(3) & ","
SQL_Text = SQL_Text & " [AddressInfoId] = " &
Me.cmb_Addr_change.Column(0) & ","
SQL_Text = SQL_Text & " [StSuffix] = '" & Me.cmb_Addr_change.Column(4) &
" ',"
SQL_Text = SQL_Text & " [Street] = '" & Me.cmb_Addr_change.Column(5) & "
',"
SQL_Text = SQL_Text & " [Street Type] = '" &
Me.cmb_Addr_change.Column(6) & " ',"
SQL_Text = SQL_Text & " [StreetDir] = '" & Me.cmb_Addr_change.Column(7)
& " ',"
SQL_Text = SQL_Text & " [Apt#] = '" & Me.cmb_Addr_change.Column(8) & " ',"
SQL_Text = SQL_Text & " [City] = '" & Me.cmb_Addr_change.Column(9) & " ',"
SQL_Text = SQL_Text & " [Prov] = '" & Me.cmb_Addr_change.Column(10) & "
',"
SQL_Text = SQL_Text & " [Postal Code] = '" &
Me.cmb_Addr_change.Column(11) & " ' "
SQL_Text = SQL_Text & " WHERE [ID]= " & (Me.txtLbl)
DoCmd.RunSQL (SQL_Text)
SQL_Text = ""
MsgBox "Completed"
End Sub