Form query....Assistance needed please!

optimus_1

Registered User.
Local time
Today, 11:51
Joined
Dec 17, 2007
Messages
49
Afternoon

I was wondering if it is possible to maintain the detail of some of the fields within a form (When inputting data) when you select to move onto the next record.

i.e.

If you have four fields. (all fields are selections from a combo box. ie Days of the week)
Field A: Monday
Field B: Tuesday
Field C: Wednesday
Field D: Thursday

And you want fields A and B to maintain the same data as the previous record when moving onto the next record. i.e.

Field A: Monday
Field B: Tuesday
Field C:
Field D:

I was wondering if this is possible and if so how is it done?.

Thanks
 
When you say "to move onto the next record" do you mean move to a new record?

If so, the standard way of doing this involves assigning the current value of a control to the default value of that same control in the control's AfterUpdate event.
The code for this, depending on the data's datatype, would be

For Text fields

Private Sub YourTextControlName_AfterUpdate()
If Not IsNull(Me.YourTextControlName.Value) Then
YourTextControlName.DefaultValue = """" & Me.YourTextControlName.Value & """"
End If
End Sub

For Numeric fields

Private Sub YourNumericControlName_AfterUpdate()
If Not IsNull(Me.YourNumericControlName.Value) Then
YourNumericControlName.DefaultValue = Me.YourNumericControlName.Value
End If
End Sub

For Date fields

Private Sub YourDateControlName_AfterUpdate()
If Not IsNull(Me.YourDateControlName.Value) Then
YourDateControlName.DefaultValue ="#" & Me.YourDateControlName & "#"
End If
End Sub

However, because you're using a combobox to populate your textboxes, you can't use the textbox's AfterUpdate event; when a textbox is populated using code, its AfterUpdate event doesn't fire. So to work around this, we'll use the form's AfterUpdate event!

Code:
Private Sub Form_AfterUpdate()
  FieldA.DefaultValue = """" & Me.FieldA & """"
  FieldB.DefaultValue = """" & Me.FieldB & """"
End Sub

Now, when you move to a new record, the A and B fields we be populated with the A and B values from the last record. This will be lost, of course, when the form is closed, until the first new record is saved.
 
Last edited:
Thankyou for the guidance it was very useful.
However i must be doing something slightly wrong with regards the comboBox field.

I have written the following code:

Private Sub Form_AfterUpdate()
OperatorID.DefaultValue = """" & Me.OperatorID & """"
Clock_Number.DefaultValue = """" & Me.Clock_Number & """"
Week_End_Date.DefaultValue = """" & Me.Week_End_Date & """"
End Sub

(clock_Number) and (Week_End_Date) are text boxes and are working perfectly as i would like but (OperatorID) is a ComboBox and isn't working exactly as i would like.

i.e.
If the first four records entered have the same (clock_Number), (Week_End_Date) and (OperatorID) then it works fine but if on the fifth record these details all require changing then only the text boxes can be changed. The ComboBox is not able to change.

Thankyou for your help
 

Users who are viewing this thread

Back
Top Bottom