Results 1 to 9 of 9
  1. #1
    lionel is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2012
    Posts
    5

    send text box value from form to another form


    I am working on transfering a text box value from a form to another form, the value is used to filter the data in the other form.
    I have tried to use openForm with a WHERE statement, but I found it was not working..

    Form1:a text box called [t1]
    Form2:a text box called [t2]

    What I want is to set the value of [t2] from [Form2] as the value of [t1] from [Form1], by clicking the button in [Form1] to openForm [Form2].
    The value of [t2] from [Form2] will be used to filter the data in [Form2].


    Please give me a help, thx!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Will both forms remain open?

    ControlSource of t2: = Forms.Form1.t1

    Or use OpenArgs argument of DoCmd.OpenForm to pass value of t1. Then the ControlSource of t2: =[OpenArgs]
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    lionel is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2012
    Posts
    5
    Hi. Both forms will remain open.
    I have found a way to use OpenArgs argument, but there is an error when click the button in Form1.
    Could you please help me to check is there anything wrong? THX!

    Command1 is a button.
    Private Sub Command1_Click()
    Dim FormName As String
    FormName = "Form2"
    DoCmd.OpenForm FormName, acNormal, , , , acWindowNormal, Me.t1
    End Sub


    This is the load event of Form2.

    Private Sub Form_Load()
    Dim id As String
    If Not IsNull(Me.OpenArgs) Then
    id = Me.OpenArgs
    Me(t2) = id
    End If
    End Sub

  4. #4
    lionel is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2012
    Posts
    5
    Since the value of [t2] from [Form2] will be used to filter the data in [Form2], do I need to do like this?

    Me.Filter = "t2= " & Me.OpenArgs

    But I still got an error when clicking the Command1 button..

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    What is the error message?

    Guess I should have asked why the WHERE clause was not working. If you want form to open to only one record, the WHERE clause is the best approach.

    Are t1 and t2 also field names?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    lionel is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2012
    Posts
    5
    It says there is an error when opening the on click event, and showed the error message
    "A problem occurred while Microsoft Office Access was communicating with the OLE server or ActiveX Control"

    I have tired using WHERE before, but I still got an error..
    [t2] = Forms![Form1]![t1]
    Hope you can give me an example so that I can know if I typed the syntax wrong.

    Both t1 and t2 are the names of the text boxs in the forms, and the values are string.

    Thx!

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Concatenate variables. Reference to field or control on form is a variable.

    DoCmd.OpenForm FormName, acNormal, , "t2=" & Me.t1 , , acWindowNormal

    That assume number fields. If text type use apostrophe delimiters:

    DoCmd.OpenForm FormName, acNormal, , "t2='" & Me.t1 & "'" , , acWindowNormal

    Where t2 is needs to be name of field in the form's RecordSource, not name of textbox.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    lionel is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2012
    Posts
    5
    I think your syntax is correct, but I don't know why I still failed to implement the onClick event.
    Anyway, thanks a lot.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    If you want to provide project, will look at. Follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Send Form without Access installed
    By Daniela in forum Forms
    Replies: 3
    Last Post: 02-07-2012, 07:07 AM
  2. send a form via mail
    By Fabdav in forum Forms
    Replies: 1
    Last Post: 10-12-2011, 07:35 AM
  3. send email from a form
    By maxbre in forum Programming
    Replies: 4
    Last Post: 11-12-2010, 01:43 AM
  4. To feild in send object from Form
    By forrestapi in forum Forms
    Replies: 16
    Last Post: 07-29-2010, 03:05 PM
  5. Send Primary Key from a Form To A Report
    By nkuebelbeck in forum Forms
    Replies: 1
    Last Post: 03-18-2010, 12:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums