go to existing record

joemeshuggah

Board Regular
Joined
Jul 18, 2008
Messages
161
i have a form in access that associates an owner to a device. i am trying to get the form to behave so that if i try to enter a new record for an existing owner, it tells me that there is already a record for that owner (in which case i would be forced to go to that record and make updates rather than inserting a new record). the code below works fine...but when i go the existing record to make updates, the same test is run and i cannot make the updates. how do i get around this?

' Query to see if there are any records with the OWNER entered
Set rsResult = dbsCurrent.OpenRecordset _
("select count(*) as CNT from (select * from tblCurrOWNER where OWNER = '" & Me.OWNER & "') as tbl")
Result = rsResult![CNT]

'If there are, deny transaction
If Result <> 0 Then
MsgBox "The OWNER already has a current record. This change will not be made."
Me.Undo
rsResult.Close
GoTo EndIt
End If
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
In your If statement, you only deal with <>0. In fact you close the recordset.

eg: your code logic:
If record exists
Close and exit

You could have
If record exists
Show message "a record already exists"
else (record doesn't exist)
create a record
Endif


I'm not clear on Update the record???

Do you have tables for People , Devices, a junction table for OwnsDevice?
Can a person own multiple devices?
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,726
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top