Results 1 to 5 of 5
  1. #1
    megatronixs is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    91

    use Like to get the fisrt 3 characters from a text box and run query

    Hi all,

    I have the below code. I try to check a textbox to see which are the first 3 characters to run query1 or query2.


    I don't seem to get it work and I don't know why. There are 2 branches that start with 3 first numbers (12388765) and the rest of the numbers is the store number.
    Any chance I do something wrong?

    Code:
     Option Compare Database
    Option Explicit
    Sub Check_first_branch_nr_Click()
    If Me.branch_txt Like "988*" Then
    query_results1
    Else
    query_results2
    End If
    End Sub
     
     
    Private Sub query_results1()
    Dim stDocName As String
    stDocName = "Query1"
    DoCmd.OpenQuery stDocName, acNormal, acEdit
    End Sub
    Private Sub query_results2()
    Dim stDocName As String
    stDocName = "Query2 UBN"
    DoCmd.OpenQuery stDocName, acNormal, acEdit
    End Sub

    Greetings.

  2. #2
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    what does 'don't seem to get it work' mean? you get an error? wrong query runs? no query runs? or what

  3. #3
    megatronixs is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    91
    Hi Ajax, nothing runs, no queries no nothing.

  4. #4
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    are you sure the code is running when you click the Check_first_branch_nr control?

    To check, in the vba window, click on the grey vertical bar to the left on your first line of code - 'If Me.branch_txt....

    a maroon dot will appear which is a break point. Then click the control, the code should stop at this line. You can then step through each line of code by hitting the F8 button. If the code does not stop, it is not running so check you have [Event Procedure] against the click event of the control and that the control is called Check_first_branch_nr

  5. #5
    megatronixs is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    91
    Hi Ajax,
    It is working now :-) They just provided me the wrong branch numbers and that is why it did not run.
    One can pull all his hair out like that..............

    Greetings.

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

Similar Threads

  1. Replies: 4
    Last Post: 07-14-2015, 11:41 AM
  2. Text box with more than 255 characters
    By ssissons in forum Forms
    Replies: 6
    Last Post: 07-25-2014, 08:32 AM
  3. Replies: 7
    Last Post: 06-20-2014, 08:55 PM
  4. Replies: 9
    Last Post: 02-11-2013, 03:09 PM
  5. enter more than 255 characters in a text box
    By reddy4305 in forum Access
    Replies: 2
    Last Post: 10-26-2010, 06:29 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