Results 1 to 10 of 10
  1. #1
    luckydead is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2020
    Posts
    25

    Function as boolean

    Hello,
    i have a problem making this function to boolen.



    I want to make if boolen is false then to return back to main sub, not to continue with next stuff in code

    Code:
    Public Function InputBoxTest()
        inputData = InputBox("What is your select?" & vbCrLf & "You will need to write again the select number" & vbCrLf & "This will generate automatic the design view in the end.", "Select ID")
        If inputData = "" Then
            'MsgBox inputData
            MsgBox "Please enter some number"
            Exit Function
        End If
    End Function
    Code:
    Public Function InputBoxTest() as Boolean
    Dim permit As Boolean
     inputData = InputBox("What is your select?" & vbCrLf & "You will need to write again the select number" & vbCrLf & "This will generate automatic the design view in the end.", "Select ID")
        If inputData = "" Then
            permit = False
            MsgBox "Please enter some number"
        Else
            permit = True
        End If
        InputBoxTest=permit
    End Function
    I'm not sure do i make it correct.

    and in my main form code when press button, if InputBoxTest returns false then to return back in sub.

    Code:
    Private Sub Command21_Click()
    
    if InputBoxTest = False Then
    Exit Sub
    End if
    
    End Sub

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    that is not how you use a function - you need to call it

    if InputBoxTest = False Then
    Not sure what you are doing to paste your code, but it is very difficult to read with the html code mixed in

    edit - see you have fixed it

    now realise you have not declared inputData as a string within the function

  3. #3
    luckydead is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2020
    Posts
    25
    so you mean to change Public Function to Public Sub ?

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    I'd test that it returns 'something', but for something like that I'd just use InputBox in the actual code?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    luckydead is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2020
    Posts
    25
    my question was does i make correct the function and check in main form.
    If i make some mistake to correct me how it should be correct way.

    For now it works for me the result. The idea is to use it in function because i will call different stuff and i do not want to write tons of lines, better 1 function call and do the trick.

  6. #6
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,159
    Your function will work but how are you returning the value input into the input box?
    And if this is a general function how would you ensure that if a date was required instead of a string or a number that it was validated?

    I admire you trying to re-use or modularise your code, but the text in this example makes it very single purpose.

    It would probably be better a sub within the form or just put a control on the form that requires this and check it's contents.
    If you need to check more than one thing on the form before running the action, then you can loop through the required controls and present a single message box telling the und user what is missing.

    Repeatedly prompting a user for inputs in to input boxes is not a great way to get data IMHO, use a form and it gives you much better control over what the user is doing.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  7. #7
    luckydead is offline Novice
    Windows 10 Office 365
    Join Date
    Nov 2020
    Posts
    25
    yeah, the problem was that i cannot call the Select method from the Query design and use it in function, thats why only option was for me to make additional box that user will put the same select number second time, so the function to work correct. I just didn't find any information related to this from Query Design, my field is "select" text and it has properties as " Like [your select] , and i just cant find a good way to get from this the same number.

    Thank you, for confirm that this way that i manage the stuff is correct.
    Im newbie as VBA, but as vb.net would be better for me doing stuff ;]

  8. #8
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,159
    If you had a form with the "Select" number control on it, you can refer to it in queries provided the form is open.

    By the way SELECT is a dreadful name for a field or control as it is a SQL statement use in almost every query!


    In your query it would read something like

    Code:
    SELECT field1 , field2 
    FROM tbYourTable
    WHERE Field3 = [Forms]![YourFormName]![YourControlName]
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  9. #9
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    so you mean to change Public Function to Public Sub ?
    no - your calling code is not calling the function

    however sounds like you are having users interact directly with the query which is not a good idea. As others have said, use a form with a textbox control for the user to enter a value and a button to open the query if something has been entered

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    In fact use a combo, so they can only enter a value that exists?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Trouble using boolean variable
    By database_1 in forum Programming
    Replies: 4
    Last Post: 05-21-2020, 01:35 PM
  2. Replies: 10
    Last Post: 01-24-2020, 06:33 PM
  3. Boolean search?
    By elamadon0228 in forum Queries
    Replies: 10
    Last Post: 11-09-2016, 12:49 PM
  4. simple boolean syntax ?
    By markjkubicki in forum Forms
    Replies: 3
    Last Post: 03-05-2013, 06:26 PM
  5. Combining two boolean values
    By John_B in forum Access
    Replies: 6
    Last Post: 02-11-2012, 11:45 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