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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Access 2002 Pop-up form go to new record and prefill some data

Status
Not open for further replies.

RickSchadt

Technical User
Dec 8, 2009
7
US
I have a pop-up form that carrys some data with it from the originating form (customer number specifically), When I pop up the form I want it to go to a new record, but I also want the customer number carried with it. I'm a VBA newby, but essentially what I want to do is after the form goes to the acNewRec I want to fill the cust_number with the cust_number_main data.

Private Sub Command40_Click()
On Error GoTo Err_Command40_Click

Dim stDocName As String


stDocName = "Transfer Form"
DoCmd.OpenForm stDocName
DoCmd.GoToRecord acActiveDataObject, , acNewRec


Exit_Command40_Click:
Exit Sub

Err_Command40_Click:
MsgBox Err.Description
 
I display the fields on the pop up form using
=Forms!MainTransferForm!Customer
 
I initially tried setting the default value of the field on the subform, and it worked initially until I executed the code that goes to the new record, then the default value is wiped out.
 
Did you set the "Default Value" property or just the Control Source/Value?

Actually, I would send the value to the new form using OpenArgs. However, the default value should also work.

Duane
Hook'D on Access
MS Access MVP
 
I set the value on the control source under properties default value. Not sure how to do the openargs.
 
Control Source" and "Default Value" are both properties. I don't know which one you set or how you did it.

Code:
Private Sub Command40_Click()
On Error GoTo Err_Command40_Click

    Dim stDocName As String
    stDocName = "Transfer Form"
    DoCmd.OpenForm stDocName , , , , , , Me.Customer
    DoCmd.GoToRecord acActiveDataObject, , acNewRec
    
Exit_Command40_Click:
    Exit Sub

Err_Command40_Click:
    MsgBox Err.Description 
....
Then in the Transfer Form on Open Event, you would use code like:
Code:
If Len(Me.OpenArgs & "") > 0 Then
   Me.txtcust_number.DefaultValue = Me.OpenArgs
End If

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top