unbound form

Eljefegeneo

Still trying to learn
Local time
Today, 10:06
Joined
Jan 10, 2011
Messages
902
This is going to sound a little crazy, but I have an unbound form with 5 fields. When I open the form which is used to run one or more reports, there is data in the fields. I remember entering data there a long time ago, but I do not remember why this form opens with data. It says it is an unbound form and there are no events to put data in the form.

How can this be? Isn't an unbound form void of data? If it is saving the data somehow, how can I change the data and when I open it up the new data is now present.

I know I can make a new table with five fields and bind it, but what am I missing here?
 
Check out the Properties window for each Control on the Form and look for the *Default Value* line. Clear or change whatever you have there.
 
I'd say either your controls have default value property setting, or the control source is set to a function call or expression.
 
Sometimes you miss the very simple explanations. Thank you.
 
I found this post: https://access-programmers.co.uk/forums/showthread.php?t=146183
As I want to change the default value programmatically with vba.

Code:
  Private Sub YourNumericControlName_AfterUpdate()
 If Not IsNull(Me.YourNumericControlName.Value) Then 
  YourNumericControlName.DefaultValue = Me.YourNumericControlName.Value
 End If
End Sub
Code:
  OperatingCost.DefaultValue = Me.OperatingCost.Value
  End Sub
Which did not change the default value. So I added a save:

Code:
  OperatingCost.DefaultValue = Me.OperatingCost.Value
  DoCmd.Save
But still no change. Is this because it is an unbound form. Going in and editing the control's default value is not an option.

Any suggestions? Again, I know I can add a small table, but surely one can do this with vba.
 
Got it!!

Code:
  Dim newCost As Double
  newCost = Me.OperatingCost.Value
  Dim myFrm As String
  myFrm = "frmMyOpenForm"
  DoCmd.Close acForm, myFrm
  DoCmd.MyOpenForm myFrm, acDesign, , , acFormPropertySettings, acHidden
      Forms!OpenForm.DefaultValue = newCost
      DoCmd.Close acForm, myFrm, acSaveYes
  DoCmd.OpenForm myFrm
To persevere is to figure it out. Of course making a small table would have taken about five minutes and then bind the form, but this is more satisfying!
 
Not sure I see the point in worrying about the default value property of an unbound control in this case.

Your initial problem was that when opened the form had data in controls. Now you want it to have values? Then just set them rather than redesigning the form every time this procedure runs?
 
or you can reset it on the Form's Load event:
Code:
Private Sub Form_Load()
With Me
    ![unboundText1] = Null
    ![unboundText2] = Null
    ….
    ….
End With
End Sub
 
Eljefegeneo:
BTW, I took it that with OpenForm,
Forms!OpenForm.DefaultValue = newCost

you just forgot the "my" part
Forms!myOpenForm.DefaultValue = newCost but then I realized this doesn't make sense either
DoCmd.MyOpenForm myFrm,


and don't use Me!someControlName unless you don't want the reference to be evaluated on compile. Use Me.someControlName
 
Last edited by a moderator:
default value is for Controls not for Forms.
 
default value is for Controls not for Forms.
Maybe specify who you're directing your comment to?? If me, I know that - which was the either part of

I realized this doesn't make sense either
Not much of that code makes sense to me.
 

Users who are viewing this thread

Back
Top Bottom