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

Form/SubForm with Pre-Fill information ???

Status
Not open for further replies.

mickeync

Programmer
Jan 26, 2003
28
US
Hi,
On my 1st form call "Customer profile". The user will pick the customer they want. When they click on OPEN FORM which appear on the CUSTOMER PROFILE, they want to see some of the info that show on the CUSTOMER PROFILE to pre-fill on my 2nd form such as Name, address, Phone, ... in order to save user time NOT to type the same information over again... then they can fill out the rest of the 2nd form. Any advice ??? I really appreciate any help.
 
If you are using DoCmd.OpenForm, you can use the OpenArgs paramater to pass a formatted string containing the field name and value:
Code:
    strValues = "ID=42|Name=Fred Flintstone"
    DoCmd.OpenForm "frmCustProf",,,,,,strValues
    ...
    'frmCustProf code module
    Dim mstrValues As String

    Sub Form_Open()
        mstrValues = Me.OpenArgs
    End Sub

Sub Form_Load()
    Dim varColumn As Variant
    Dim varValue As Variant

    Dim intColumn As Integer
    Dim intValue As Integer
    Dim intStart As Integer

    intStart = 1
    Do While intStart > 0
        intColumn = InStr(intStart, mstrValues, "=")
        varColumn = "[" & Mid(mstrValues, intStart, intColumn - intStart) & "]"
        intStart = intColumn + 1
        intValue = InStr(intStart, mstrValues, "|")
        If intValue Then
            varValue = Mid(mstrValues, intStart, intValue - intStart)
        Else
            varValue = Mid(mstrValues, intStart, Len(mstrValues) - intStart + 1)
        End If
        
        intStart = intValue
        If intValue Then
            intStart = intValue + 1
        End If
        Me.Controls(varColumn) = varValue
    Loop
End Sub
Above assumes that form's control names match column names. Jim Kraxberger
Developing Access solutions since 1995
 
Hi Jim,
Thanks for your response !!! I am just a new kid on the block. Your coding is way above my head... and I am trying to understand. It might take me a while to figure out, thank you in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top