Hi Don,
Ok, the fundamental complication here is caused by the fact that you're not normalizing your database correctly. In other words what you're doing is fundamentally "wrong" - although yes, you can do it.
What you should be doing is storing the SecurityId value in a Users:SecurityId field. That way you would have access to the security table, and hence to the SecurityLevel and SecNumber. If wither of these details should be changed then _all_ the users on that Security Id would "get" the change.
But ok, you may not be in control of this, so you have what you have. There are two basic problems here;
a) when the form opens in change mode you need to prime the drop-down to select the correct record from the Security table. You don't actually know which record to display because the one thing not stored in the Users table is the Security Id.
b) when the form is completed you need to read the values from the security table, and store them in the Users table.
So here's what I suggest you do.
a) remove the Users:SecurityLevel field and Users:SecNumber fields from the form.
b) create a local field, say loc:SecurityId to take its place. This variable will be primed when the form is opened, and will be used when the form closes.
The code, when the form closes, looks something like this;
Access:Security.Open()
Access:Security.UseFile()
Sec:SecurityId = p_web.GSV('loc:SecurityId')
Access:Security.Fetch(Sec:KeySecurityId)
Users:SecurityLevel = Sec:SecurityLevel
Users:SecurityNumber = Sec:SecNumber
Access:Security.Close()
p_web.SSV('Users:SecurityLevel',Users:SecurityLevel)
p_web.SSV('Users:SecurityNumber',Users:SecurityNumber)
It goes into the ValidateRecord routine. So it will be executed when the user clicks on Save.
The second bit of code should go at the top of the PreUpdate routine. This is where you determine, from the current values in the User file, what the loc:SecurityId should be. Something like;
Access:Security.Open()
Access:Security.UseFile()
set(Sec:KeySecurityId)
loop until Access:Security.Next()
If Users:SecurityLevel = Sec:SecurityLevel and |
Users:SecurityNumber = Sec:SecNumber
loc:SecurityId = sec:SecurityId
p_web.SSV('loc:SecurityId',loc:SecurityId)
break
end
end
Access:Security.Close()
I haven't run all the above, so you may need to check the code etc.
Personally I'd normalize the database - unnormalized data causes lots of work pretty much everywhere they go.
cheers
Bruce