Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unbound form: How to trigger Dirty 1

Status
Not open for further replies.

iamareplicant

Programmer
Aug 7, 2004
50
US
Experts,

I have a complex 2k3 Access form that is unbound. The data for the form comes from several different Oracle tables that cannot be joined, etc.

There are several subforms on this form, and several groups of controls on the form, all unbound.

My question: Is there a way to simulate a Diry event trigger of ANY value on the form that gets changed?

Because the form in question is itself a subform on a tab, I dont want the user to be able to go to another tab if they have changed something on the current tab's form without saving the changes.

My worst scenario is having to put a flag on every control's change event, etc. to capture a change :(

Thoughts?

TIA,

JBG
 
Is looping through the record and checking the relevant control an option? Say:
Code:
For Each fld In rs.Fields
    If fld <> Me("txt" & fld.Name) Then
        blnIsDirty = True
    End If
Next
 
Wont work. I populate the controls manually (all controls are unbound), then when ready for the insert or update, i read the values from the control and create an SQL statement.

So, the recordset itself never gets changed until I run an insert or an update manually AFTER the user hits add/Save.

What i need to be able to do is find out if any unbound control on a form has had its value changed. IF they try to go to another tab without saving their changes, i need to throw up a warning....
 
I am afraid I do not quite understand. I had imagined that each control was originally populated from a recordset so that the initial value of the control is the value in the record. If the control contains data that is different from the record, it has been changed. However, you say that the controls are populated manually; how is this done?
 
Sure, here is a very rough psuedo code:

Code:
set rst = dbs.OpenRecordset("SomeRecSet")
while not rst.eof
         for x  = 0 to rst.fields.count
            if rst.fields(x).name = "Cat" then
              txtCat = rst.fields(x).value
            end if
            if rst.fields(x).name = "Dog" then
              txtDog = rst.fields(x).value
            end if
             ......etc
   


         next x
 rst.movenext
wend

Each control in question is not bound. I populate it manually as done above. As mentioned ealier, there is no recordsource for the form that would allow for one query, say, to work. But come to think of it, I guess I could make a ton of sub forms and then check those for Dirty. But then again, I am trying to find a way to avoid that.

I was hoping to find a way to have a form express a change done to an unbound control....

Jeff
 
maybe I can just use keydown and mousedown on the form and set a flag if either get triggered, regardless if the user doesnt change anything...so, I can send up a msgbox like

"A value may have been changed. Change tabs without saving?"

if the flag gets set to true...

Really cheesy, but I need to do soemthing...
 
What I suggested is a reverse, in a way, of the population of the form. That is:

[tt]set rst = dbs.OpenRecordset("SomeRecSet")
for x = 0 to rst.fields.count - 1
if Me("txt" & rst.fields(x).name).Value <> rst.fields(x).value Then
'Field has changed
blnFieldChanged=True
end if
next x[/tt]

I cannot see why this will not work, run in an appropriate event. The 'For each fld' loop seemed easier, when I tested, both for populating the form and for testing to see if the record had changed. However, I may still be missing an important point as I don't see why you are moving to the next record in the recordset without a next button or such like. [ponder]

 
Dude, you rock. You nailed it.

Without going into detail re: your final question, you gave me exactly what I need i think.

I alreay use the .tag to store the field name on each control. So,

I can look through the controls on the form,
check the .tag against the record set field name
Check the value of that control against the value of the recset(field)
If different, dirty.
Ugh, wish i would have thought of it. It was right in front of me.

Thanks for your time. Much obliged.

Jeff
 
How are ya iamareplicant . . .

Welcome to the world of problems [purple]Unbound[/purple] can cause! ;-)
iamareplicant said:
[blue]Because the form in question is itself a subform on a tab, I dont want the user to be able to go to another tab if they have changed something on the current tab's form [purple]without saving the changes[/purple].[/blue]
Since saving is the bottom line here, might I suggest if the user changes tabs, you do the saving in code yourself! . . . regardless if the user has saved or not. It may be a double save, but whats the difference if the user goes back, makes no changes, and hits save again.

For detection of the process you could use the tab controls Change event along with the Screen Object to determine if you've just left the tab the subform in question is on.

Just an Idea but something like this:
Code:
[blue]Private Sub TabCtlName_Change()
   If SubWasPrev Then Call YourSaveRoutine
End Sub

Public Function SubWasPrev() As Boolean
   Dim frm As Form, ScnNam As String, ctl As Control
   
   Set frm = Forms!MainFormName!subFormName.Form
   ScnNam = Screen.ActiveControl.Name
   
   For Each ctl In frm.Controls
      If ctl.Name = ScnNam Then
         SubWasPrev = True
         Exit For
      End If
   Next

   End Function[/blue]
There are other things you may need to do but this just an Idea so far.

[blue]Your thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Ace,

That is along the right lines, but saving everytime someone leaves a form/tab is going to cost time for the user.

When a user clicks "SAVE" on a form (which is indeed a large subform on a tab control), I go thru many processes to not only refresh the form they are looking, but updating other forms embedded in the other 5 tabs to show the changes they just made.

So, i dont want to to thru a "save" if they havent made any changes. If I always do a "save" when they leave a tab, then transversing the tabs will take a considerable amount of time (after all, each tab change would require an entire save routine).
 
Roger That iamareplicant . . .

Again . . . it was just an Idea! . . .

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top