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

    Make a dim control work with a function to pass information

    I have a function with controls

    however on one form I don't have the control available and do not want to add it so I thought about = the field into a variable that is a control



    I have

    Code:
    Private Sub Command128_Click()
    Dim conAddress As control
    conAddress = [SchoolAddress]
    
    
    Call googleMapsAddress(conAddress, Me.SchoolSuburb, Me.SchoolState)
    End Sub
    on the call googlemapsaddress() they have to be controls

    so I thought passing the info from the field into the control could work but it doesn't - any suggestions?

  2. #2
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Note I can change the function to variables and that works fine for my task'

    but I would still like to learn if it is possible and how...

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    What is googleMapsAddress ?

    Is this a custom function? The first argument needs to be a Control? That does not make sense. Can you post the first line of the googleMapsAddress function?

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

    I'm still working on it (making it use directions next)

    at the moment it just opens to maps

    Code:
    
    Function googleMapsAddress(conAddress As Variant, conSuburb As Variant, conState As Variant)
    
    
    'OPEN ADDRESS IN IE OR CHROME
    'makes strings to be used below
    Dim strWebLink As String, strURL As String, strAddress As String, strSuburb As String, strState As String
    
    
    
    
    strWebLink = "http://maps.google.com/maps?q="
    'trims the code
    strAddress = conAddress
    strAddress = Trim(strAddress)
    'removes double space
    strAddress = Replace(strAddress, "  ", " ")
    'replaces spaces to +
    strAddress = Replace(strAddress, " ", "+")
    
    
    'repeat for suburb
    strSuburb = conSuburb
    strSuburb = Trim(strSuburb)
    strSuburb = Replace(strSuburb, "  ", " ")
    strSuburb = Replace(strSuburb, " ", "+")
    
    
    'repeat for state
    strState = conState
    strState = Trim(strState)
    strState = Replace(strState, "  ", " ")
    strState = Replace(strState, " ", "+")
    
    
    'join strings into one url
    strURL = strWebLink & "+" & strAddress & "+" & strSuburb & "+" & strState
    
    
    'open browser with link
    Application.FollowHyperlink strURL
    
    
    
    
    End Function

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    To match the function you would have this in your click event.

    Dim conAddress As variant
    conAddress = Me![SchoolAddress]

    Did not look at the entire function...

  6. #6
    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 ItsMe View Post
    To match the function you would have this in your click event.

    Dim conAddress As variant
    conAddress = Me![SchoolAddress]

    Did not look at the entire function...
    at the moment I have it variant hence I am guessing that is why you picked "as variant" for conAddress

    but what if in the function I had "as control" and wanted to make dim conaddress as control

    would conaddress = me![schooladdress] still work?

  7. #7
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    No, your function is looking for a variant as the first argument. You can pass it a string, integer, etc. but, it has to be able to fit into a Variant type. I do not believe controls fit into Variants.

    Besides, what you want is the data from the field. It should fit into a string since you have strAddress as string type. Is conAddress text and all in one, continuous line?

  8. #8
    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 ItsMe View Post
    No, your function is looking for a variant as the first argument. You can pass it a string, integer, etc. but, it has to be able to fit into a Variant type. I do not believe controls fit into Variants.

    Besides, what you want is the data from the field. It should fit into a string since you have strAddress as string type. Is conAddress text and all in one, continuous line?
    I meant if I made the function a control instead of a variant

    Function googleMapsAddress(conAddress As control, conSuburb As control, conState As control)

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Hmmm, I have never tried it. As far as I know, the control is an object and you can probably get properties from it. The problem would be you would have to create the control, virtually, in the form's module, assign a field to it, and then some how refresh the control. Then, maybe be able to reference the control in the function. Then, pull its .Value.

    It might work. Seems like a lot of trouble for something you could just place directly from the Recordset to a string Variable
    Dim strAddress As string
    strAddress = Me![SchoolAddress]

    There is not a need to create a control on your form to store a field that is in the recordset. Use the above VBA to store the value in a string variable.

  10. #10
    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 ItsMe View Post
    Hmmm, I have never tried it. As far as I know, the control is an object and you can probably get properties from it. The problem would be you would have to create the control, virtually, in the form's module, assign a field to it, and then some how refresh the control. Then, maybe be able to reference the control in the function. Then, pull its .Value.

    It might work. Seems like a lot of trouble for something you could just place directly from the Recordset to a string Variable
    Dim strAddress As string
    strAddress = Me![SchoolAddress]

    There is not a need to create a control on your form to store a field that is in the recordset. Use the above VBA to store the value in a string variable.

    yeah, I've gone with another method anyway but it's still something I like to try

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

Similar Threads

  1. How to Pass ListBox to Function?
    By RedGoneWILD in forum Programming
    Replies: 4
    Last Post: 03-05-2013, 12:13 PM
  2. Replies: 3
    Last Post: 03-29-2012, 12:40 PM
  3. Replies: 3
    Last Post: 12-28-2010, 12:42 PM
  4. Replies: 4
    Last Post: 02-11-2010, 02:21 AM
  5. pass a variable to the MsgBox function
    By 3dmgirl in forum Programming
    Replies: 2
    Last Post: 04-19-2007, 07:14 AM

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