Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    LittleRock Z is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2024
    Posts
    18

    command button on a form, what is the VBA code to ask user a question and user reply


    The question to the user will be like enter LOT number, and the user reply would be a 3 characters. The purpose of the command button is to position the table / file to a specific record.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2021
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Quote Originally Posted by LittleRock Z View Post
    The question to the user will be like enter LOT number, and the user reply would be a 3 characters. The purpose of the command button is to position the table / file to a specific record.
    You could use a message box to get the users reply but a better way, might be to use the wizard to create a combo box. Select the 3rd option (Find a record on my form based on the value I selected in my combo box). Access will then do all the work for you using macros. Access will even convert the macros to vba code for you with the click of a button.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Input box Bob, not message box?
    I would probably just use a normal textbox.
    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

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2021
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Quote Originally Posted by Welshgasman View Post
    Input box Bob, not message box?
    I would probably just use a normal textbox.
    Thank you Welshgasman. Another "Senior Moment" I'm afraid. I was, of course, thinking of an Inputbox.
    Curious to know why your preference would be for a textbox to find a record rather than a combo?
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by Bob Fitz View Post
    Thank you Welshgasman. Another "Senior Moment" I'm afraid. I was, of course, thinking of an Inputbox.
    Curious to know why your preference would be for a textbox to find a record rather than a combo?
    I too would use a combo, but only for a set number of options?
    If the user has 60k+ records etc and each has a unique value that is going in the combo, then finding it would be a little laborious, even typing character by charcter?. I now use a FAYT class for my combos as well, but that is a step up from normal VBA. Easy to implement though TBH.
    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

  6. #6
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    What's not known is if the user already knows the value to be input. They may be reading it off of an invoice or similar source, in which case there's no need to look it up?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    LittleRock Z is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2024
    Posts
    18
    The Combo box provides a list for the user to choose from.
    What I want is for the user to tell me the part number, and I will move to and display the matching record.

  8. #8
    LittleRock Z is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2024
    Posts
    18
    The user does know the number, and I want to locate the record and display it.
    If the number is not found, the user can get a "No Find, try again"

  9. #9
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    566
    Quote Originally Posted by LittleRock Z View Post
    The Combo box provides a list for the user to choose from.
    What I want is for the user to tell me the part number, and I will move to and display the matching record.
    Why would you do that? The whole point of a good UI is to not make the user guess or pick invalid options.

  10. #10
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2021
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Quote Originally Posted by LittleRock Z View Post
    The user does know the number, and I want to locate the record and display it.
    If the number is not found, the user can get a "No Find, try again"
    So why not use a textbox (perhaps in the forms Header section)
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  11. #11
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    If you still want an input box, there are millions of posts about how to code for it so why not research that instead of us recreating the wheel here?
    Here's but one - https://www.youtube.com/watch?v=-3Z7DMTf_Pg

    What you'd also want is code that uses GoToRecord method - as long as you're not doing this directly on a table. Or you could simply apply a filter to the form (assuming you're even using one) after user OK's input box. There doesn't seem to be a lot of code examples for using input box for this, probably because it's not common to use one. Input boxes require validation, otherwise errors are commonly raised due to bad inputs. Also, the returned value is a string, which means you have to convert values in order to use them as dates or other numbers. That's why combos or listboxes are used to provide the input, which often contains the actual record ID, meaning you don't need clumsy commands like GoToRecord. If you want the best of both, use a FAYT combo to filter the combo list and then choose. Or use a listbox that automatically requeries itself as you type, thus filtering the list as you go. Then choose from the filtered list.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    LittleRock Z is offline Novice
    Windows 10 Access 2007
    Join Date
    Feb 2024
    Posts
    18
    Quote Originally Posted by Micron View Post
    If you still want an input box, there are millions of posts about how to code for it so why not research that instead of us recreating the wheel here?
    Here's but one - https://www.youtube.com/watch?v=-3Z7DMTf_Pg

    What you'd also want is code that uses GoToRecord method - as long as you're not doing this directly on a table. Or you could simply apply a filter to the form (assuming you're even using one) after user OK's input box. There doesn't seem to be a lot of code examples for using input box for this, probably because it's not common to use one. Input boxes require validation, otherwise errors are commonly raised due to bad inputs. Also, the returned value is a string, which means you have to convert values in order to use them as dates or other numbers. That's why combos or listboxes are used to provide the input, which often contains the actual record ID, meaning you don't need clumsy commands like GoToRecord. If you want the best of both, use a FAYT combo to filter the combo list and then choose. Or use a listbox that automatically requeries itself as you type, thus filtering the list as you go. Then choose from the filtered list.
    Thank you for the in-depth reply. I find it very useful thank you.
    Now for the rest of the story, which is more than than you probably care about. I am an old time assembly language programmer, and I have volunteered to resurrect the cemetery management program for a small country church cemetery. The original system was developed under contract and has since died for lack of funds to pay for its upgrades, The previous manager maintained the records by taking a page out of the master book, placing it in a typewriter, making the changes on the typewriter and putting the page back in the master book. I have one table which has 723 Records, one for each LOT, and each LOT has eight PLOTs. it is a flat table with no sub parts. All the updating forms have been completed to their satisfaction. now I have a report form for the user to review and select one for printing as a replacement page in the master book. The lot numbers are unique all 723 of them, And keyboard keys allow the user to page up and down to the record of Choice and print it, case closed. But I would like the user to tell me the LOT number and let me proceed up or down to that record for their printing,

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    I would have an unbound textbox in the form header.
    You enter a lot number. AfterUpdate event does a FindRecord on that lot number.
    Validate that it is not > than 723.

    Job done.
    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

  14. #14
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2021
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Quote Originally Posted by LittleRock Z View Post
    Thank you for the in-depth reply. I find it very useful thank you.
    Now for the rest of the story, which is more than than you probably care about. I am an old time assembly language programmer, and I have volunteered to resurrect the cemetery management program for a small country church cemetery. The original system was developed under contract and has since died for lack of funds to pay for its upgrades, The previous manager maintained the records by taking a page out of the master book, placing it in a typewriter, making the changes on the typewriter and putting the page back in the master book. I have one table which has 723 Records, one for each LOT, and each LOT has eight PLOTs. it is a flat table with no sub parts. All the updating forms have been completed to their satisfaction. now I have a report form for the user to review and select one for printing as a replacement page in the master book. The lot numbers are unique all 723 of them, And keyboard keys allow the user to page up and down to the record of Choice and print it, case closed. But I would like the user to tell me the LOT number and let me proceed up or down to that record for their printing,
    Well, IMHO, the best and easiest solution would be to use a combo box in the Header section of the form.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  15. #15
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I find the management of what happens to some of us after we pass on to be an interesting subject, so it's not more than I care to read about your problem as you say. I created a columbarium db as an exercise in design because of a similar posted situation, but I think that is overkill for your case. Point is, whatever your db is designed for, there is probably somebody waiting in the wings here who has some knowledge of the need, or at least is willing to help and perhaps interested in the concept.

    Not sure a flat file is best for your application, but something tells me you're not going to change that and are only interested in a quick solution to an immediate problem. That is OK, but just letting you know that should you ever decide to turn this into something more robust, you'll probably find that there is no shortage of help (albeit it usually comes with a lot of questions that are needed to flesh out whatever proposal someone has in mind).

    So for now, you have had a few suggestions, and they all seem to fit the requirement one way or another. You just have to decide on which way to go?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 11-17-2021, 04:50 PM
  2. Replies: 4
    Last Post: 10-29-2016, 12:20 AM
  3. Replies: 1
    Last Post: 10-27-2016, 10:51 PM
  4. Replies: 4
    Last Post: 06-01-2013, 11:32 PM
  5. Replies: 0
    Last Post: 11-22-2011, 09:10 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