Title of Message box not setting up - visual-studio-6

I am writing some code in Visual Basic 6. It also uses the Msgbox funtion. Now I searched this and I got to know that if you want to set the title of the Message box then this is the syntax:
Msgbox(<Prompt>,<Title>)
For example, I write this:
MsgBox ("Incorrect Answer!","QM")
It says:
Compile Error
Expected: =
Can someone tell me what is the problem?

With VB6, you can either request a response, and do something based on the answer, or you can simply display a message.
If you want to know what button was clicked, you need to use the function format - that is, you must use the brackets.
If you simply want to display a message, then you don't use the brackets.
So if you want to just display the message, then continue, do this:
MsgBox "Incorrect Answer!", , "QM"
But if you want to know which button the user clicked (e.g. to offer them a try again, cancel, then you need a variable, and you use the brackets to signifify that it's a function:
Dim response = MsgBox("Try again?", MsgBoxStyle.YesNo, "QM")
You can then look at the response variable to find out which button the user clicked.
A couple of pages for reference:
http://vb6reference.tomswebdesign.net/msgbox.html
https://msdn.microsoft.com/en-us/library/139z2azd(v=vs.90).aspx

Related

Problem with active status when an continue form have zero record for a filter

this is my first question here and english isnt my language but I'll try to explain at my best.
Im using MS Access 2007.
The form is a "continue form" with a header section where you find an "apply filter" button and a field named "cmpCercaCognome" (italian language for "find surname" plus "cmp" in italian language as field).
This is a cut out of the feature where I am having problems.
The function is fine if the search filter that is set in the field produces at least one result.
The function fails if there are no results.
Private Sub cmpCercaCognome_Change()
If (ActiveControl.Name = "cmpCercaCognome") Then
LunghStr = Len(Me.cmpCercaCognome.Text)
else
LunghStr = Len(Me.cmpCercaCognome)
End if
'Something else but I dont reach it
end sub
The error appear when I'm clicking in the field "cmpCercaCognome" and then Im typing a key there to change the value to use for a filter that I'll apply with a button.
The check "activecontrol" is true still the Len function give error "2185 - Cant read control... without an active status..). How? I just check that have active status! And Im typing just there...
I tryed to modify the IF check so:
"If (ActiveControl.Name = "cmpCercaCognome") And (Me.RecordsetClone.RecordCount > 0) Then"
So I can check just when the count of the record is more than 0.
The problem that so I check the .value of the field that dont contain the last pressed key.
So isnt usefull for me
Is there any way to avoid the problem by keeping control of the temporary value of the field? Or is there a way to make the "temporary value" effective right away so as to avoid checking the .text property?
Thanks for any help you can get on this.

click button VBA to update a drop down field to a specific value

I'm wanting a button to perform multiple actions. when clicked it should:
add 1 to dial attempts field
change the "leagGenOutcome" to "no answer"
the problem is that the "leadGenOutcome" is a dropdown field taking it's options from another table.
I used this VBA code which works for a field with no drop down, but doesn't work on the drop down field.
Private Sub AddDialAttBTN_Click()
DialAttempts = DialAttempts + 1
LeadGenOutcome = "no answer"
End Sub
I know I must be missing something simple to get this to work. any help is much appreciated.
EDIT
by "doesn't work" the DialAttempts counter ticks up as it should but a "run time error" displays stating "the value you entered isnt valid for this field"
LimitToList property is Yes
"no answer" is a listed item
the field that LeadGenOutcome is bound to is called LeadGenOutcome01 in a form called LeadGenOutcomes.
currently it's a test database which I am using to learn how best to arrange and format.
changed "no answer" to "2" which is the ID for that response in the linked form. I had thought that it would display as "2" and not the associated text. this is not the case. thank you June7 for the assist.

Code "delete my account" button

Im using vb 2013. I tried to code my delete button after adding SQL delete in my Database. I wrote code in the class (I called it userFunc) calling the SQL DeleteItYourself with the variable DeleteIt. I created button with the toolbox and double clicked it, now I'm lost. I have session in the Login button to make sure it presents the user nickname. I redirected it to the homepage when the "I want to delete my account" located. Iactually don't know what to do with the button. I want it to call the function DeleteIt, but before the function Delete I want it to ask the user with some pop up alert if he's sure. Any ideas how to code my button?
(I'm a high school student and it's my project, they don't ACTUALLY teach us Java, unfortunately... They tell us to copy paste and try to understand)
Use this as a starting point:
If MsgBox("Are you sure you want to delete your account? This cannot be undone.", _
(MsgBoxStyle.Critical + MsgBoxStyle.OkCancel), _
"Confirm Account Deletion") = MsgBoxResult.Ok Then
UserFunc(DeleteIt)
End If
MsgBox displays a message box to the user, waits for a response, and returns the value of the button pressed. In the code above, the three arguments are:
The message to display
The style of the message box. Note how these are numeric values and can be added.
The title of the window.

How to change the Contents of a msg box

I have a form for creating a record, I also have a button on the top of the form for to return to a form called home. When the form is being viewed and half the information is put in and the home button is clicked an error pops up saying " you cannot add or change a record beacasue a related record is required in a table "Elements"." How do I Change what the content of the error message is ?
You can put checks in your button_click sub to circumvent -- check to make sure all fields are filled in, and if not, display your own message box followed by
Exit Sub
That will short circuit the rest of the method so you should not get the standard message.
Here is a resource on error-handling in VBA: http://allenbrowne.com/ser-23a.html
I'm not sure, however, if you can create a handler in VBA for standard program error messages.

classic asp - response.redirect and response.write problem

The problem if someone types into the search box a location it goes through to that location page but if they type in a location thats not found or they dont type anything in I need it to redirect back to the homepage (index.asp) and display "whoops we couldnt find that" in the search box (input field)
This is the vb
Case Else
response.redirect "index.asp?whoops=whoops we couldnt find that"
End Select
Then in the value of the input field I have
value="<% =whoops %>"
This doesnt work by the way, first is this the best way of doing it because id rather not have the error message in the url. This there away of posting the error as a variable and then calling it into the input field like,
<% =whoops %>
You don't need the error message in the url. Also, whoops won't be available to you as a variable just because it is in the url. You have to look for it in the Request.Querystring collection. What you'd want to do is something more like this on the homepage:
Dim whoops : whoops = ""
If Request.Querystring("whoops") Then
whoops = "whoops we couldnt find that"
End If
Then you could output <%=whoops %> as the search box's HTML value attribute. This would also prevent people from being able to assign whatever they want to the value of whoops, which is a security vulnerability.