Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2015
    Posts
    17

    Help with functions

    Hello everyone,
    I have every sub procedure on this form exept for the F string function, it should have the following functionality:
    F Strings
    Input1: Assume user enters one word of at least 4 characters, no spaces.
    Input2: Assume user enters one word of at least 4 characters, no spaces.
    The click event will use a function procedure that concatenates the last 2 letters of Input2 and the first 2 letters of Input1.
    e.g. User enters dog and cat, lblAnswer displays atdo.



    but everytime I try to run it I get the run time error 13 type mismatch. Can anyone help me? I have attach my form. Thank you
    240CCA05.accdb

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why are you using Val() function? That function is to convert text strings like "472 dollars" into a number: 472
    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
    Join Date
    Jan 2015
    Posts
    17
    Hi June 7 that's for the other functions
    the one that i'm having problems with is the F Strings
    Private Sub cmdFStrings_Click()
    Dim dblResult As Double
    strInput1 = txtInput1.Value
    strInput2 = txtInput2.Value
    dblResult = Fstrings(strInput1, strInput2)
    Me.lblAnswer.Caption = dblResult
    End Sub
    Private Function Fstrings(strInput1 As String, strInput2 As String)
    Fstrings = Left(strInput2, 2) & Left(strInput1, 2)
    End Function

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    dblResult is declared as a Double. Declare it as a String. Use different name as well.

    Dim strResult As String
    ...
    strResult = ...

    Save yourself some typing - Value is default property for data controls. Don't have to specify.
    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.

  5. #5
    Join Date
    Jan 2015
    Posts
    17
    Thank you for the advice and help I didn't know you didn't have to specify them but now I do

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664

    Code:
    Private Function Fstrings(strInput1 As String, strInput2 As String)
    Fstrings = Left(strInput2, 2) & Left(strInput1, 2)
    End Function
    This will return the first two characters of strInput2 and the FIRST two characters of strInput1.


    function procedure that concatenates the last 2 letters of Input2 and the first 2 letters of Input1
    User enters dog and cat, lblAnswer displays atdo.
    I would think you would need to use the function RIGHT() strInput2 to get the last two characters:
    (code with June's suggestion)
    Code:
    Private Sub cmdFStrings_Click()
        Dim strResult As String
        strInput1 = txtInput1
        strInput2 = txtInput2
        strResult = Fstrings(strInput1, strInput2)
        Me.lblAnswer.Caption = strResult
    End Sub
    
    Private Function Fstrings(strInput1 As String, strInput2 As String)
        Fstrings = Right(strInput2, 2) & Left(strInput1, 2)
    End Function

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

Similar Threads

  1. 2 Date Functions
    By Rustin788 in forum Forms
    Replies: 1
    Last Post: 12-05-2014, 09:32 AM
  2. F functions
    By dref in forum Access
    Replies: 1
    Last Post: 08-23-2012, 06:13 AM
  3. Functions
    By Alex Motilal in forum Programming
    Replies: 2
    Last Post: 09-27-2010, 08:06 AM
  4. sum functions
    By trippers in forum Queries
    Replies: 2
    Last Post: 08-04-2010, 07:09 PM
  5. Functions
    By jamin14 in forum Programming
    Replies: 1
    Last Post: 03-25-2010, 08:16 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