Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MsgBox/InputBox Titlebars = integers? 3

Status
Not open for further replies.

jnuus

Programmer
Jul 17, 2003
29
US

Greetings Access Gods,

I've been away from the IDE for several years due to a medical event and have recently started building a db while trying to re-learn as I go (my meager coding skills have atrophied significantly in the last few years due to lack of use). Anyway, I built an event by which the user can clear the dataset with a few clicks. The problem is that my dialog boxes display integers instead of a string. When I write the title string in the line of code, it errors out. I haven't encountered this issue before... msgbox and inputbox functions are normally ez-pz, but the ones in this sub have me perplexed. Hope you can help, and thanks in advance.

Here's my code:
Code:
Private Sub cmdEraseAllRecords_Click()

Dim strKeyword As String
strKeyword = "CLEAR-ALL"
Dim strUserInputDelRec As String

Do While strUserInputDelRec <> strKeyword
 strUserInputDelRec = InputBox("To confirm deletion, type the phrase '" & strKeyword & "' (without quotes) and click OK:", vbOKCancel)
  If strUserInputDelRec = strKeyword Then
   Exit Do
  End If
 If strUserInputDelRec = "" Then Exit Sub
 If MsgBox("Incorrect entry. Try again?", vbYesNo) = vbNo Then Exit Sub
Loop
 CurrentDb.Execute "Delete * From tblMain", dbFailOnError
 MsgBox "All records have been successfully deleted.", vbOKOnly, vbInformation
Exit Sub
 
 Me.cmdFirstFocus.SetFocus

End Sub
 
vbOKCancel=1, the second default argument is Title, thus the result. The arguments have to have proper location as in argument list. You can use named arguments without special order, among others:
strUserInputDelRec = InputBox("Your message", Title:="Input title", Default:="Entry text if can help")

combo
 
This is one way:

Dim strKeyword As String, strUserInputDelRec As String
strKeyword = "CLEAR-ALL"
Do While strUserInputDelRec <> strKeyword
'strUserInputDelRec = InputBox("To confirm deletion, type the phrase '" & strKeyword & "' (without quotes) and click OK:", "ABC", strKeyword)
strUserInputDelRec = InputBox("To confirm deletion, type the phrase '" & strKeyword & "' (without quotes) and click OK:", "ABC")
If strUserInputDelRec = strKeyword Then Exit Do
If strUserInputDelRec = "" Then Exit Sub
If MsgBox("Incorrect entry. Try again?", vbYesNo, "ABC") = vbNo Then Exit Sub
Loop
CurrentDb.Execute "Delete * From tblMain", dbFailOnError
MsgBox "All records have been successfully deleted.", vbOKOnly + vbInformation, "ABC"


Herman
Say no to macros
 
To help you create any MsgBox, even the most fancy ones, you may want to get MZTools for VBA (free). One of the feature is a "MsgBox Assistant" which looks like this:

MsgBox_orlvn3.png


Type what you need, select any buttons, (set the default button, too), select icons, options, etc., preview your message box, and on the top of all of that, it will write the VBA code for you!


---- Andy

There is a great need for a sarcasm font.
 
I'm fairly certain MZTools is no longer free however it is still a great value if you write a lot of VBA.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
You are right, Duane. It used to be free.
But still, worth every penny while coding....[pc2]


---- Andy

There is a great need for a sarcasm font.
 
MZTools 3 for VBA was free and is still available for download. However, I don't know if this version integrates with VBA 7 in current office vba.
Edit:
Ooops, sorry, this link is to version 8. Maybe version 3 can be found in third party sites, but it seems that MZtools terminated version 3.

combo
 
Hey just wanted to thank all of you who responded to my post... I'm just now getting back to this because I had some out-of-state relatives show up at my door unexpectedly. All clear now :)

Anyway, I will try out your suggestions when I get back to work and let you know. Just didn't want y'all to think I was one of those drive-by OPs who get their answer and *poof* ... disappear.

Thanks again
 

Thank you so much for your help! Coding is such a perishable skill, and after several years away sometimes even the easy stuff seems like a barrier to me. After I saw your suggestions, I realized that my problem stemmed from the concatenation operation in the string ... it took me some trial and error to get it syntaxed correctly, and I over-fixated on it as the cause which left my field of view too narrow to see the real problem. Sheesh.

Anyway, your assistance is very much appreciated as always. Incidentally, I was able to locate MZ-Tools 3.0 on an archived page of the company's website. I haven't installed it because I am considering purchasing the current version, especially since it still supports VB6.

Thanks again, and peace.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top