pass value of combo from first record, to next

cdoyle

Registered User.
Local time
Today, 01:12
Joined
Jun 9, 2004
Messages
383
Hi,

I was asked today if this is possible, when the users are making entries in the form. One of the combo boxes they select is normally the same option for many records throughout the day.

What they asked if it would be possible, once they make a selection in the combo on their first record, if the value could be held and when they start the next record, that field will already be filled in.

It would hold this value until they change it, or close the form?

One way I thought it could be done is make a hidden field in my main form. When they make the selection in the field on the sub form, the hidden field will hold the value. Then when they go to the next record, somehow the combo will look at the hidden field and display whatever is held there?

Is that the correct way to do it, or is there a better method?
 
Last edited:
Thanks!
This looks pretty good, but how does it work?

I've tried copying the code over to my form, and adding the checkboxes to my form. But when I press the command button it doesn't do anything.

So I must be missing something, or not seeing something.
 
In your form, you can use the AfterUpdate event of the control holding your data to set the DefaultValue for the field. From that time forward, until you either manually change the data or close your form, the data will be entered automatically in each new record. The syntax varies slightly, depending on the datatype of the data:

For Date fields

Code:
Private Sub YourDateControlName_AfterUpdate()
If Not IsNull(Me.YourDateControlName.Value) Then
  YourDateControlName.DefaultValue ="#" &  Me.YourDateControlName & "#"
End If
End Sub
For Text fields

Code:
Private Sub YourTextControlName_AfterUpdate()
If Not IsNull(Me.YourTextControlName.Value) Then
  YourTextControlName.DefaultValue = """" & Me.YourTextControlName.Value & """"
End If
End Sub
For Numeric fields

Code:
Private Sub YourNumericControlName_AfterUpdate()
If Not IsNull(Me.YourNumericControlName.Value) Then
  YourNumericControlName.DefaultValue = Me.YourNumericControlName.Value
End If
End Sub
 
you can't copy the code over to the form doyle. even if you copy code that has a sub called "cmdfill_click()", which is what this is called, and then put a button on your form called "cmdfill", it will not work, because it is not registered as an actual event behind the control. If that is indeed what you did, go to the EVENTS tab behind the button, and push the (...) after the ONCLICK line, and that will register the procedure behind the button. Try it again...
 

Users who are viewing this thread

Back
Top Bottom