Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

auto copy in a form 3

Status
Not open for further replies.

Ju

Technical User
Jul 4, 2000
61
0
0
FR
hi,<br>I have a form in which I'd like to copy automatically the content of a field I just entered in the same field in the next record I will create. <br><br>Thanks for your help.
 
How about using the DLast() function?<br><br>In your form, set the Default Value for the field you want automatically filled in to<br>=DLast(&quot;Field#1&quot;,&quot;YourTableName&quot;)<br>
 
in the code of the form put in the following <br><br>&nbsp;&nbsp;&nbsp;&nbsp;Dim value As String<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;value = Text2<br>&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.Save<br>&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.GoToRecord , , acNewRec<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Text2 = value<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>that will get the value entered into the textfield save it go to a new record and set the textfield value. <br> <p>Walt III<br><a href=mailto:SAElukewl@netscape.net>SAElukewl@netscape.net</a><br><a href=
 
mmhhh, it actually didn't really talk a lot to me...<br>I am definitely a newbie to visual basic and I need real deep explantions... The Dlast function doesn't work for me.<br>here is what i have:<br>a table named --&gt; pre<br>a form named&nbsp;&nbsp;--&gt; detail<br>in this form a field&nbsp;&nbsp;--&gt; SIRET<br><br>in the properties of the field, in the form, i put:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=Dlast(SIRET,detail)<br>And nothing, it tells me that it's not a valid expression.<br><br>For the other code, i need more explanation for where to put it.<br><br>Thank you very much.
 
If you use the second code you need to put&nbsp;&nbsp;it in the place that takes you to the next form for example if you want them to go to the next form as soon as the data is entered you put it in the befofe update section of the textfield's code or if you want them to push a button and go to a new form put it in the code for the button.<br><br> <p>Walt III<br><a href=mailto:SAElukewl@netscape.net>SAElukewl@netscape.net</a><br><a href=
 
actually, I want that when all my data is inputed in my form that when going to a second record some fields are copied to this new record.<br><br>Also, I tried the code you gave me and it actually failed.<br>Am I supposed to let it this way? Don't I need to put an object name?<br><br>Thank you very much.
 
Ju,<br><br>If I understand you properly, after you enter data in one record in a form, you want the values you entered in certain fields to show up for the next new record.<br><br>You can do this by resetting the DefaultValue Property.<br><br>On your form, in EVERY field that you want to have values automatically filled in put the following code in the AfterUpdate Event<br><br>me!YourFieldName.DefaultValue =Me!YourFieldName<br><br>Let me know how it works.<br><br>Kathryn
 
Ok, <br>so I go to the code section, then:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-choose form<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-choose AfterUpdate --&gt; something appears<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-I type the code below what appeared:<br><br>appeared&nbsp;&nbsp;--&gt;&nbsp;&nbsp;Private Sub Form_AfterUpdate()<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Me!SIRET.DefaultValue = Me!SIRET<br><br>appeared&nbsp;&nbsp;--&gt;&nbsp;&nbsp;End Sub<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>I save, and run my form and it tells me:<br>Object doesn't support this property or method<br><br>...Any idea?<br>Thank you
 
OK, you put the code in the AfterUpdate event of the FORM, you need to put it in the AfterUpdate event of the textboxes you want to fill in.<br><br>So if there are five textboxes you want to fill in with the value of the previously entered record, you will paste the code in five times.<br><br>Don't forget to delete the code from the form's AfterUpdate event!&nbsp;&nbsp;;-)<br><br>Kathryn
 
ok, so here is what i did:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Private Sub SIRET_N°_AfterUpdate()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Me!SIRET.DefaultValue = Me!SIRET<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End Sub<br>And it keeps on doing the same fault...sniff ;)<br><br>hmmm, i'm lost.<br>Other ideas to help?<br>thanks
 
Question:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Private Sub SIRET_N°_AfterUpdate()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Me!SIRET.DefaultValue = Me!SIRET<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End Sub<br><br>Your code has SIRET_No as the name in the Private Sub line, but only SIRET in the next line.&nbsp;&nbsp;Is this just a translation issue?<br><br>What is SIRET?&nbsp;&nbsp;Is it a textbox?&nbsp;&nbsp;If so, try<br><br>Me!SIRET.DefaultValue = Me!SIRET.text<br><br>although that shouldn't be necessary.<br>
 
Try this<br><br>in the form's code module add a module level variable, add a function to capture the input into the textbox, update the variable in the AfterUpdate() Event, and use the function as the default value for the textbox.<br>(i.e. the default property box for the textbox you named SIRET:&nbsp;&nbsp;&nbsp;= MyDefault()<br><br>Option Compare Database<br>Option Explicit<br>Dim strTxtSIRET As String<br><br>Private Sub SIRET_AfterUpdate()<br>strTxtSIRET = SIRET<br>End Sub<br><br>Function MyDefault()<br>MyDefault = strTxtSIRET<br>End Function
 
Go back to the Dlast function for a moment.<br><br>Did you type in<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=Dlast(SIRET,detail)<br><br>or&nbsp;&nbsp;&nbsp;&nbsp;=Dlast(&quot;SIRET&quot;,&quot;pre&quot;)<br><br>You need the quotes to identify the string values, and the underlying table name, not the form name.&nbsp;&nbsp;With the quotes and the table name this should be the easiest solution.
 
Another thing about the autocopy...<br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Private Sub SIRET_N°_AfterUpdate()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Me!SIRET.DefaultValue = Me!SIRET.text<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End Sub<br><br>It works only when I fill all the input mask...<br>My input mask is 99999999999999<br>&nbsp;&nbsp;&nbsp;&nbsp;if I enter&nbsp;&nbsp;&nbsp;12345678901234 It works and autocopies it.<br>&nbsp;&nbsp;but if I enter 123456&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;It fails and puts in the<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next entry #Name?<br><br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top