I'll have to read up on the different syntax you just mentioned and see what I can make of it, notably the .OpenForm method.
Are you addressing me? I liked the idea in point 2 of post 2, and tried to implement it but it seems a bit cumbersome. After playing around, I see that it will make a difference as to how your form is working. If you can cycle through records where any of these values are Null, you will need to handle that with the Nz function. I think the property to use for the default with the BeforeUpdate event is .Text, since that reflects what is visible in the control at the moment before the update, which might be different from the actual control value. Moving from record to record changes the control value but not the default, even on a new record, so that seems OK. However, if the form can cycle on to a new record, the .Text value becomes invalid and generates the #Name? error, so that has to be handled too.
What I tried was
- in design view of the form select a control you whose values you want to retain
- invoke the code builder, BeforeUpdate event and type or paste
Code:
Me.txtControlName.DefaultValue = Nz(Me.txtControlName.Text, "")
where txtControlName is the name of your control.
To handle the move to a blank record, I see the OnCurrent event for the form as the place to go, but trying to work with a control that has an invalid value generates a strange error (2247). The solution seems to be, handle the error and substitute a value like so:
Code:
Private Sub Form_Current()
On Error GoTo errHandler
If Me.PRIMARY = "#Name?" Then
'the above will generate error 2247 if the control contains an invalid value
With Me.txtControlName
.SetFocus
.DefaultValue = Me.txtControlName.Text
End With
End If
Exit Sub
errHandler:
If Err.Number = 2447 Then
Me.txtControlName = Null 'or whatever default is desired. 'This will allow a
'record if the value passes table validation, which may not be desired
Resume Next
End If
End Sub
Ajax - feel free to correct me as this was your idea; I just had a bit of free time and an intrusive nature At this point, globals or temp tables are looking more attractive because of the number of controls involved. I know, I can be fickle.