UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> How To Copy The Value Of Form Textbox To A New Open Form, Access 2007    
 
   
ayen
post May 24 2020, 03:47 PM
Post#1



Posts: 976
Joined: 9-May 13



Hello everyone,

I have a continuos form wherein theres a button inline with otber textbox, that when i click it it will open a new form and i want to copy the Resident ID from the previous form to the ID number textbox of the new open form..

Thank you,
Ayen
Go to the top of the page
 
June7
post May 24 2020, 03:52 PM
Post#2



Posts: 1,512
Joined: 25-January 16
From: The Great Land


Are you trying to create a dependent record? This is a common topic. Can use OpenArgs to pass a value. Or second form can reference control on first form. Either way, need VBA.

Consider alternative https://www.fmsinc.com/MicrosoftAccess/Form...kedSubforms.asp

--------------------
Attachments Manager is below the edit post window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Go to the top of the page
 
projecttoday
post May 24 2020, 03:55 PM
Post#3


UtterAccess VIP
Posts: 12,376
Joined: 10-February 04
From: South Charleston, WV


Also the WHERE condition might be of use in your case if you're using Docmd.OpenForm.

--------------------
Robert Crouser
Go to the top of the page
 
DanielPineault
post May 24 2020, 06:54 PM
Post#4


UtterAccess VIP
Posts: 7,375
Joined: 30-June 11



OpenArgs are great for this type of thing, or to give one more options to consider, using TempVars can also be helpful.

--------------------
Daniel Pineault (2010-2020 Microsoft MVP, UA VIP, EE Distinguished Expert 2018)
Professional Help: https://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: https://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
fogline
post May 24 2020, 07:42 PM
Post#5



Posts: 228
Joined: 5-August 15
From: Ringgold, GA. USA


Another technique is to use the AutoFillNewRecord()function described later in this article. You can call this function from a form's OnCurrent property event procedure to fill all the fields in a new record using data from the previous record. If you want to fill only selected fields, you can create a text box and set the DefaultValue property with a semicolon-delimited list of control names to automatically fill, for example:
Text box:
-----------------------------------------------
Name: AutoFillNewRecordFields
Visible: No
DefaultValue: Phone;Company Name;City;State;Zip

To create and use the AutoFillNewRecord() function, follow these steps:
Open the sample database Northwind.mdb.
Create a module and type the following line in the Declarations section:

Option Explicit

Type the following procedure:

Function AutoFillNewRecord(F As Form)

Dim RS As DAO.Recordset, C As Control
Dim FillFields As String, FillAllFields As Integer

On Error Resume Next

' Exit if not on the new record.
If Not F.NewRecord Then Exit Function

' Goto the last record of the form recordset (to autofill form).
Set RS = F.RecordsetClone
RS.MoveLast

' Exit if you cannot move to the last record (no records).
If Err <> 0 Then Exit Function

' Get the list of fields to autofill.
FillFields = ";" & F![AutoFillNewRecordFields] & ";"

' If there is no criteria field, then set flag indicating ALL
' fields should be autofilled.
FillAllFields = Err <> 0

F.Painting = False

' Visit each field on the form.
For Each C In F
' Fill the field if ALL fields are to be filled OR if the
' ...ControlSource field can be found in the FillFields list.
If FillALLFields Or InStr(FillFields, ";" & (C.Name) & ";") > 0 Then
C = RS(C.ControlSource)
End If
Next

F.Painting = True

End Function


Save the module as modAuto_Fill_New_Record.
Open the Customers form in Design view. Change the OnCurrent property of the form to read as follows:

=AutoFillNewRecord([Forms]![Customers])

Add a text box to the form, and set the following properties:
Text Box
----------------------------------------------------------
Name: AutoFillNewRecordFields
Visible: No
DefaultValue: CompanyName;ContactName;ContactTitle;Address

Note This sample setting for the text box works only in the Northwind sample database. For your own database, you can set the DefaultValue property with a semicolon-delimited list of control names.
When you go to a new record, the CompanyName, ContactName, ContactTitle, and Address fields are filled in automatically. If you want all fields to automatically be filled in, you can leave the DefaultValue property blank or omit putting the AutoFillNewRecordFields text box on the form.

--------------------
Ray White - Fog Line Software LLC.
Email
Go to the top of the page
 
June7
post May 24 2020, 07:47 PM
Post#6



Posts: 1,512
Joined: 25-January 16
From: The Great Land


@fogline, appreciate contribution to discussion but could you please put code between CODE tags to retain indentation and readability?


--------------------
Attachments Manager is below the edit post window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Go to the top of the page
 
ayen
post May 24 2020, 09:31 PM
Post#7



Posts: 976
Joined: 9-May 13



Many thanks june7,

Can you please guide me through on the openargs, how to use it. I am not familiar yet with openargs and so with coding.

Thanks,
Ayen
Go to the top of the page
 
tina t
post May 24 2020, 09:45 PM
Post#8



Posts: 6,671
Joined: 11-November 10
From: SoCal, USA


see Microsoft Help topic for DoCmd.OpenForm. when you put a value in the OpenArgs argument, Access sets the OpenArgs property of the form that you're opening, to the value you provided. you can refer to the property anywhere in the form you opened, for instance

Me!MyIDNumberTextboxName = Me.OpenArgs

hth
tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 
June7
post May 24 2020, 09:49 PM
Post#9



Posts: 1,512
Joined: 25-January 16
From: The Great Land


Or like:

If Me.NewRecord Then Me!ID_FK = Me.OpenArgs


--------------------
Attachments Manager is below the edit post window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Go to the top of the page
 
ayen
post May 25 2020, 06:53 AM
Post#10



Posts: 976
Joined: 9-May 13



Hi tina,

Where should i put the code? Please guide me through..

Many thanks,
Ayen
Go to the top of the page
 
ayen
post May 25 2020, 06:54 AM
Post#11



Posts: 976
Joined: 9-May 13



Hi june7,

Where should i put the suggested code?.

Many thanks,
Ayen
Go to the top of the page
 
orange999
post May 25 2020, 08:05 AM
Post#12



Posts: 2,110
Joined: 10-February 08
From: Ottawa, Ont, Canada; West Palm Beach, FL


ayen,

See this article from FMS on Open Args with examples.
Or this thread from UA
This post has been edited by orange999: May 25 2020, 08:09 AM

--------------------
Good luck with your project!
Go to the top of the page
 
June7
post May 25 2020, 11:00 AM
Post#13



Posts: 1,512
Joined: 25-January 16
From: The Great Land


Second form Load or Current event.

--------------------
Attachments Manager is below the edit post window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Go to the top of the page
 
ayen
post May 26 2020, 01:44 AM
Post#14



Posts: 976
Joined: 9-May 13



Hi june7

I put the below on OnCurrent/OnLoad of second form;

If Me.NewRecord Then
Me.ResID = Me.OpenArgs
End If

It did not copy the ResID of the first form into the second form.

Can you please check what is the problem.

Many thanks
Ayen
Go to the top of the page
 
ayen
post May 26 2020, 01:59 AM
Post#15



Posts: 976
Joined: 9-May 13



Hi orange999,

I tried the below behind cmdbutton;

DoCmd.OpenForm "frmVitalStatus", OpenArgs:=Me.ResID

but it did not copy the ResID of the first form.

Can you pls help.

Many thanks
Ayen
Go to the top of the page
 
DanielPineault
post May 26 2020, 04:17 AM
Post#16


UtterAccess VIP
Posts: 7,375
Joined: 30-June 11



Passing the OpenArgs when opening the form is just the 1st step, then you need to tell the form what to do with the information.

From the calling form, you do:
CODE
DoCmd.OpenForm "frmVitalStatus", , , , , , Me.ResID


Then, in the form itself, you do:
CODE
Private Sub Form_Load()
    If Not IsNull(Me.OpenArgs) Then
        Me.ResID = Me.OpenArgs
    End If
End Sub

--------------------
Daniel Pineault (2010-2020 Microsoft MVP, UA VIP, EE Distinguished Expert 2018)
Professional Help: https://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: https://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
June7
post May 26 2020, 04:47 AM
Post#17



Posts: 1,512
Joined: 25-January 16
From: The Great Land


A form can be opened to existing records for edit or to only enter a new record. Same form can be used for both. So be careful about code that sets a field value. Don't want code to edit existing record. So if you want to use Load event to populate field, then open form in Add mode.

DoCmd.OpenForm "frmVitalStatus", , , , acFormAdd , , Me.ResID

Otherwise, put code to set field value in Current event and test for either NewRecord as I suggested or if field is null.

If IsNull(Me.ResID_FK) Then Me.ResID_FK = Me.OpenArgs

This does put record in edit mode and commits autonumber if you have autonumber key field. An alternative is to set control's DefaultProperty so field will be populated when user begins entry in another field.

This post has been edited by June7: May 26 2020, 04:55 AM

--------------------
Attachments Manager is below the edit post window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Go to the top of the page
 
ayen
post May 26 2020, 10:40 PM
Post#18



Posts: 976
Joined: 9-May 13



Hi Daniel,

Thank you for picking up my post.. it works now.

Many thanks,
Ayen
Go to the top of the page
 
ayen
post May 26 2020, 10:44 PM
Post#19



Posts: 976
Joined: 9-May 13



Hi june7,

Many thanks for your time effort..

Ayen.
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    4th July 2020 - 01:23 PM