How to make such a form?

ariansman

Registered User.
Local time
Yesterday, 23:21
Joined
Apr 3, 2012
Messages
157
There is a form with blanks which are bound to a table. we put data and press the record button and go to the next record. In the next record, blanks are empty. How can we make the form to still keep the previous data in the blank? For example, there is employee name: Jack, we press the record bottom. In the next record, we want the blank to still show Jack ,otherwise we write the name of another employee.
thank you
 
In your form properties, on the Data tab, set the data entry line to NO.

Alan
 
The setting 'No' for the data entry line is set by default so I guess that your form has this setting already.With it, the desired feature does not work, at least on my computer it didn't.

I hope you have some knowledge in VBA. If so, try the following (adapted to your application of course):

In the code module of your form put this:

Option Compare Database
Option Explicit

Private Type tpMyRecord
mrField1 As String
mrField2 As Integer
End Type

Private mTpMyRec As tpMyRecord


Private Sub cmdCopyRecord_Click()
Call GetControlValues
End Sub

Private Sub Form_AfterUpdate()
Call GetControlValues
End Sub

Private Sub Form_Current()
If Me.NewRecord And mTpMyRec.mrField1 <> vbNullString Then
txtField1.Value = mTpMyRec.mrField1
txtField2.Value = mTpMyRec.mrField2
End If
End Sub

Private Sub GetControlValues()
mTpMyRec.mrField1 = txtField1.Value
mTpMyRec.mrField2 = txtField2.Value
End Sub



Note that the userdefined variable 'mTpMyRec' is filled only after a form update. In order to have the functionality without an update, you can add a commandbutton to your form (here 'cmdCopyRecord') and get the values manually.
 
Nice little package StarGrabber.

Another, slightly 'simpler' way, would be to set the default value of each control to the current value BEFORE moving to the new record

Code:
Dim dQuote as String
dQuote = """"   'thats 4 quotes
me!ControlName.DefaultValue = dQuote & me!ControlName.Value & dQuote
Just repeat for each control you want to 'copy' over.

The only downside is that the next time you open the form the default value will be the value you last typed in.
 
Re: slightly 'simpler' way

Well done Isskint. I can't find the 'downside' you mentioned. Using both your code and mine there are no preset values after opening the form because there was no form update event.

But I found other downsides:

With your code it's not possible to use string values containing quotes, like ' My string value "test" ' or ' "Test value" ' but I think ariansman wouldn't be annoyed with this.

And with my code it's not possible to use empty fields. So you have to add a check of every control value with either the Nz function or with an If block:

in case of a string field:
mTpMyRec.mrField1 = Nz(txtField1.Value, "")

in case of a numeric field:
mTpMyRec.mrField1 = Nz(txtField1.Value, 0)

works with both cases:
If Not IsNull(txtField1.Value) Then
mTpMyRec.mrField1 = txtField1.Value
End If

StarGrabber
 

Users who are viewing this thread

Back
Top Bottom