473,385 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Message box Option Buttons

28
I have a search function in my database, see below:-

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSearch_Click()
  2.     Dim SerialNumberRef As String
  3.     Dim Search As String
  4.  
  5. 'Check txtSearch for Null value or Nill Entry first.
  6.  
  7.     If IsNull(Me![txtsearch]) Or (Me![txtsearch]) = "" Then
  8.         MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
  9.         Me![txtsearch].SetFocus
  10.     Exit Sub
  11. End If
  12. '---------------------------------------------------------------
  13.  
  14. 'Performs the search using value entered into txtSearch
  15. 'and evaluates this against values in SerialNumber
  16.  
  17.  
  18.     DoCmd.GoToControl ("SerialNumber")
  19.     DoCmd.FindRecord Me!txtsearch
  20.  
  21.     SerialNumber.SetFocus
  22.     SerialNumberRef = SerialNumber.Text
  23.     txtsearch.SetFocus
  24.     Search = txtsearch.Text
  25.  
  26. 'If matching record found sets focus in SerialNumber and shows msgbox
  27. 'and clears search control
  28.  
  29.     If SerialNumberRef = Search Then
  30.         MsgBox "Match Found For: " & Search, , "Congratulations!"
  31.         SerialNumber.SetFocus
  32.         txtsearch = ""
  33.  
  34.     'If value not found sets focus back to txtSearch and shows msgbox
  35.         Else
  36.            MsgBox "Match Not Found For: " & Search & " - Please Try Again.", _
  37.             , "Invalid Search Criterion!"
  38.             txtsearch.SetFocus
  39.     End If
  40. End Sub
When the search finds the serial number it displays a message box with "Ok"
Because I have multiple entries with the same serial the search always only finds the first record.
Is there a way to adapt the above code so it displays a message box with 2 option buttons, one that says "Ok" and one that says "Next" whereby I can then use the Find Next function to search for the remaining serial numbers?

Ezzz
May 10 '10 #1

✓ answered by ADezii

This is the General idea:
Expand|Select|Wrap|Line Numbers
  1. 'If matching record found sets focus in SerialNumber and shows msgbox
  2. 'and clears search control
  3. Dim intResponse As Integer
  4.  
  5. 'Hopefully, SerialNumberRef and Search are Declared/Initialized somewhere
  6. If SerialNumberRef = Search Then
  7.   intResponse = MsgBox("Match Found For: " & Search, , vbRetryCancel, "Congratulations!")
  8.     If intResponse = vbRetry Then
  9.       'Do your FindNext Operation
  10.       DoCmd.FindNext
  11.     Else
  12.       'Satisfied by initial Find
  13.       DoCmd.Close   'Close the Form & Set Focus to a Control on it?
  14.       SerialNumber.SetFocus
  15.       txtsearch = ""
  16.     End If
  17. 'If value not found sets focus back to txtSearch and shows msgbox
  18. Else
  19.   MsgBox "Match Not Found For: " & Search & " - Please Try Again.", _
  20.           , "Invalid Search Criterion!"
  21.                txtsearch.SetFocus
  22. End If

12 5839
missinglinq
3,532 Expert 2GB
Instead of using a Messagebox, you'll have to "roll your own," using a Popup/Modal form instead, with your own buttons. This is the standard workaround when you need a 'messagebox' that does things or looks differently from what an actual Messagebox can do or look.

Linq ;0)>
May 10 '10 #2
ADezii
8,834 Expert 8TB
@Ezzz
Is there a way to adapt the above code so it displays a message box with 2 option buttons, one that says "Ok" and one that says "Next" whereby I can then use the Find Next function to search for the remaining serial numbers?
As linq explained, you would have to Roll Your Own, unless you wished to use a Message Box with Retry and Cancel Options, as in:
Expand|Select|Wrap|Line Numbers
  1. Dim intResponse As Integer
  2.  
  3. intResponse = MsgBox("Okie Dooky", vbRetryCancel, "YaDa - Yada")
  4.  
  5. If intResponse = vbRetry Then
  6.   'Do your FindNext Operation
  7. Else    'Cancel or Close Button
  8.   'Satisfied by initial Find
  9. End If
May 10 '10 #3
Ezzz
28
ADezii
I did like your solution and tried to re-code my search formula but got bogged down with too many "If" statements. See below:-
Expand|Select|Wrap|Line Numbers
  1. 'If matching record found sets focus in SerialNumber and shows msgbox
  2. 'and clears search control
  3.  
  4.     If SerialNumberRef = Search Then
  5.         MsgBox "Match Found For: " & Search, , vbRetryCancel, "Congratulations!"
  6.         If Search = vbRetry Then
  7.         DoCmd.FindNext
  8.         'Do your FindNext Operation
  9.         Else
  10.         DoCmd.Close
  11.         'Satisfied by initial Find
  12.         SerialNumber.SetFocus
  13.         txtsearch = ""
  14.  
  15.     'If value not found sets focus back to txtSearch and shows msgbox
  16.         Else
  17.            MsgBox "Match Not Found For: " & Search & " - Please Try Again.", _
  18.             , "Invalid Search Criterion!"
  19.             txtsearch.SetFocus
As you may see I am very new to Vb coding and most of what I am using has been gleened from examples found on the net, but I am trying.

Ezzz
May 10 '10 #4
NeoPa
32,556 Expert Mod 16PB
Ezzz, you have been told a number of times now to use the CODE tags when posting code. Please do so in future.

-Administrator.
May 10 '10 #5
ADezii
8,834 Expert 8TB
@Ezzz
Syntax is all wrong, I'll rewrite and return later.
May 10 '10 #6
ADezii
8,834 Expert 8TB
This is the General idea:
Expand|Select|Wrap|Line Numbers
  1. 'If matching record found sets focus in SerialNumber and shows msgbox
  2. 'and clears search control
  3. Dim intResponse As Integer
  4.  
  5. 'Hopefully, SerialNumberRef and Search are Declared/Initialized somewhere
  6. If SerialNumberRef = Search Then
  7.   intResponse = MsgBox("Match Found For: " & Search, , vbRetryCancel, "Congratulations!")
  8.     If intResponse = vbRetry Then
  9.       'Do your FindNext Operation
  10.       DoCmd.FindNext
  11.     Else
  12.       'Satisfied by initial Find
  13.       DoCmd.Close   'Close the Form & Set Focus to a Control on it?
  14.       SerialNumber.SetFocus
  15.       txtsearch = ""
  16.     End If
  17. 'If value not found sets focus back to txtSearch and shows msgbox
  18. Else
  19.   MsgBox "Match Not Found For: " & Search & " - Please Try Again.", _
  20.           , "Invalid Search Criterion!"
  21.                txtsearch.SetFocus
  22. End If
May 10 '10 #7
Ezzz
28
Firstly apologies to the administrator re-the coding tags, hopefully I now understand where I was going wrong.

Secondly ADezi thanks for the responce tried your code but couldn't get it to work.
I have adapted it slightly (see below) and it nearly works!
When it carries out the "DoCmd.FindNext" function the search does indeed find the next serial number but ONLY the next one. What I'd hoped was to be able to keep retrying until it finds the desired item. Is there a way to loop the function?
Furthermore the close function is wrong. The "DoCmd.Close" actually wants to close the form and all I wanted it to do was stop the search. Also it doesnt like the SerialNumber.SetFocus txtsearch = "" after the close, but when i remove them it throws up a debug problem and highlights the DoCmd.Close statement.
Any ideas

Ezzz

Expand|Select|Wrap|Line Numbers
  1. 'If matching record found sets focus in SerialNumber and shows msgbox
  2. 'and clears search control
  3.  
  4. Dim intResponse As Integer
  5.  
  6. 'Hopefully, SerialNumberRef and Search are Declared/Initialized somewhere
  7.  
  8.     If SerialNumberRef = Search Then
  9.         intResponse = MsgBox("Match Found For: " & Search, vbRetryCancel, "Congratulations!")
  10.         SerialNumber.SetFocus
  11.         txtsearch = ""
  12.  
  13.     If intResponse = vbRetry Then
  14.       'Do your FindNext Operation
  15.       DoCmd.FindNext
  16.     Else
  17.       'Satisfied by initial Find
  18.       DoCmd.Close   'Close the Form & Set Focus to a Control on it?
  19.       SerialNumber.SetFocus
  20.       txtsearch = ""
  21.     End If
  22.  
  23.     'If value not found sets focus back to txtSearch and shows msgbox
  24.         Else
  25.            MsgBox "Match Not Found For: " & Search & " - Please Try Again.", _
  26.             , "Invalid Search Criterion!"
  27.             txtsearch.SetFocus
  28.     End If
  29. End Sub
May 12 '10 #8
NeoPa
32,556 Expert Mod 16PB
Ezzz: Firstly apologies to the administrator re-the coding tags, hopefully I now understand where I was going wrong.
Good to hear Ezzz.

I can be PMed if you have any difficulties. I'm always happy to help members with the techniques of using the forum well and fully.

-NeoPa.
May 12 '10 #9
ADezii
8,834 Expert 8TB
The basic concept would be:
Expand|Select|Wrap|Line Numbers
  1. Do
  2.   intResponse = MsgBox("Find Another Match?", vbRetryCancel, "Continue Find")
  3.     DoCmd.FindNext
  4. Loop Until intResponse = vbCancel
May 12 '10 #10
Ezzz
28
Thanks ADezii
Almost works now, one minor flaw left, when i select the retry button the search does go to the next serial number in line and so on, great.
But when i find the asset i want and press the cancel button the search jumps one asset and displays the next in line not the one i stopped on?
See code below:-
Expand|Select|Wrap|Line Numbers
  1. 'If matching record found sets focus in SerialNumber and shows msgbox
  2. 'and clears search control
  3.  
  4. Dim intResponse As Integer
  5.  
  6. 'Hopefully, SerialNumberRef and Search are Declared/Initialized somewhere
  7.  
  8.     If SerialNumberRef = Search Then
  9.         intResponse = MsgBox("Match Found For: " & Search, vbRetryCancel, "Congratulations!")
  10.         SerialNumber.SetFocus
  11.         txtsearch = ""
  12.  
  13.     If intResponse = vbRetry Then
  14.       'Do your FindNext Operation
  15.       DoCmd.FindNext
  16.     'If this is not the asset you are looking for then try again
  17.     Do
  18.     intResponse = MsgBox("Find Another Match For: " & Search, vbRetryCancel, "Continue Find")
  19.     DoCmd.FindNext
  20.     Loop Until intResponse = vbCancel
  21.  
  22.     Else
  23.       'Satisfied by initial Find and close search
  24.  
  25.     End If
May 13 '10 #11
ADezii
8,834 Expert 8TB
Try:
Expand|Select|Wrap|Line Numbers
  1. Do
  2.   intResponse = MsgBox("Find Another Match For: " & Search, vbRetryCancel, "Continue Find")
  3.     If intResponse = vbRetry Then DoCmd.FindNext
  4. Loop Until intResponse = vbCancel
May 13 '10 #12
Ezzz
28
Well done thats it you've cracked it.
Much appreciated.
Regards
Ezzz
May 13 '10 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Edward | last post by:
I have a data entry form that allows the user to navigate around entirely using the keyboard. However, it contains various option button controls which are in the tab order. Whenever they are...
5
by: Saxman | last post by:
I created a text box labeled txtText1. The text box has a sample of text within. The Enabled property is set to False and the Multiline property set to True. I have four option buttons set...
2
by: PM | last post by:
I have a question about option buttons and their values. I have many option buttons on my forms, each set contained in their own group boxes. I simply want to be able to give them a value,...
2
by: Omey Samaroo | last post by:
I have had many questions answered in this forum and I am trusting that one of the readers may help me find a simple solution. (1) Using a field called Date_Hired (type: Date/Time), how do I use...
0
by: Robert | last post by:
Stephen, I think I figured out the problem. I was able to get Check Boxes and Option Buttons to work on my form by TURNING OFF RECORD SELECTORS on the form. Not sure why this would make a...
5
by: tsnyder | last post by:
I need to have an option button that allows editing to a field only when it is checked.
0
by: sselvi | last post by:
Hi! I am using the visual basic applications in powerpoint to create a program which will enable the user to enter a mulitiple choice question and options for that question. For eg. if the user...
1
by: MAIjah | last post by:
Sorry, just a newbie and what I call a 'bruteforce' programmer. I'm using a VBform in EXCEL to pass info to a worksheet. I have 7 option buttons (exclusive?, only one can be true) and want to...
21
beacon
by: beacon | last post by:
Hello to everybody, I have a section on a form that has 10 questions, numbered 1-10, with 3 option buttons per question. Each of the option buttons have the same response (Yes, No, Don't know),...
1
by: ahmed222too | last post by:
how to use the option buttons in VBA (how to call the value of the option buttons ) and is it must to gather the option buttons in one option group ? thanks
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.