Results 1 to 8 of 8
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    reference form and form control


    I am making a function that opens a form and fills the text box with that number while also filtering the form

    I have

    Code:
    
    
    
    Function filterSchoolPostCodes(FormName As Form, Postcode As String, FillField As control)
    
    
    If Len(Postcode) <> 5 Or lenpostcode <> 4 Then
    Else
    
    
    
    
    Dim PostcodeConverted As Integer
    PostcodeConverted = CInt(postcodefield)
    
    
    DoCmd.OpenForm (FormName), , , "[numberInt] between " & (PostcodeConverted + 5) & " And " & (PostcodeConverted - 5) & ""
    Forms!(FormName).Form.FillField.Value = PostcodeConverted
    
    
    End If
    End Function
    
    Private Sub PostCode_DblClick(Cancel As Integer)
    Call filterSchoolPostCodes(frmSchoolsSearchPostCode, Me.Postcode, txtPostCode)
    End Sub
    What I don't know is how to correctly reference the formname and the textbox on the field in my code.

    any recommendations?

  2. #2
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Code:
    Private Sub PostCode_DblClick(Cancel As Integer)
    Call filterSchoolPostCodes("frmSchoolsSearchPostCode", Me.Postcode, "txtPostCode")
    End Sub
    
    
    Function filterSchoolPostCodes(FormName As String, Postcode As String, FillField As String)
    
    
    If Len(Postcode) <> 5 Or Len(Postcode) <> 4 Then
    Else
    
    
    
    
    Dim PostcodeConverted As Integer
    PostcodeConverted = CInt(postcodefield)
    
    
    DoCmd.OpenForm FormName, , , "[numberInt] between " & (PostcodeConverted + 5) & " And " & (PostcodeConverted - 5) & ""
    Forms!FormName.Form.FillField.Value = PostcodeConverted
    
    
    End If
    End Function

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    now using this

    Code:
    Function filterSchoolPostCodes(Postcode As Control)
    
    
    If Len(Postcode) = 5 Or Len(Postcode) = 4 Then
    Dim strStore As String
    strStore = Postcode
    
    
    
    
    Dim PostcodeConverted As Integer
    PostcodeConverted = CInt(strStore)
    
    
    
    
    
    
    DoCmd.OpenForm "frmSchoolsSearchPostCode", , , "[numberInt] between " & (PostcodeConverted + 5) & " And " & (PostcodeConverted - 5) & ""
    
    
    Forms!frmSchoolsSearchPostCode!txtPostCode.Value = PostcodeConverted
    
    
    
    
    
    
    Else
    End If
    
    
    End Function
    however I would still like to know how to pass form names and controls through a function.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I typically pass them as strings and use:

    Forms(FormVariablename).Controls(ControlVariableNa me).Value
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by pbaldy View Post
    I typically pass them as strings and use:

    Forms(FormVariablename).Controls(ControlVariableNa me).Value
    ah I didn't have .controls or .forms

  6. #6
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I get compile error, identifier or bracket expression

  7. #7
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    oh wait

    Forms(FormToOpen).Controls(ControlToPassPostCode). Value = PostcodeConverted

    works - thanks

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 5
    Last Post: 08-02-2013, 11:20 AM
  2. Replies: 7
    Last Post: 03-19-2012, 12:56 PM
  3. Control Reference on a Form
    By gmitchell@exbrief.com in forum Forms
    Replies: 5
    Last Post: 01-24-2011, 12:31 PM
  4. Variable within form control reference
    By Tyork in forum Programming
    Replies: 2
    Last Post: 10-13-2010, 09:55 AM
  5. Can't reference control in subform
    By evanscamman in forum Forms
    Replies: 0
    Last Post: 12-25-2007, 06:47 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