Message Boxes!

robbielove
03-04-2004, 02:05 PM
I know this is silly, but im just learning Visual Basic. And, i was wondering how do you put the contents a string eg. sqlString into a Message box. I thought it was something like MsgBox "Welcome ,sqlString,. Thank You for logging in. Click ok to continue." but that doesn't work. All replies greatly appriciated.
Robert Love.

zeek
03-04-2004, 02:08 PM
msgbox("text" & variable)

Zeek

00100b
03-04-2004, 02:09 PM
You can concatenate a string value contained in a variable into a literal string in something like the following manner.

MsgBox "Welcome, " & sqlString & ". Thank you for logging in. Click OK to continue."

Robert Drake
03-04-2004, 02:09 PM
Try
MsgBox "Welcome , " & sqlString & ",. Thank You for logging in. Click ok to continue.",, "Welcome"

robbielove
03-04-2004, 02:12 PM
Ok thanks but that didn't quite bring up what i expected! It just said Welcome SELECT from Customer ........ Thank You for logging in.
I have a database with the table Customer and i want to show Cust_Name instead of the SQL statement. Is this possible?

zeek
03-04-2004, 02:16 PM
You have to do the SQL query first, of course, and assign the result to a variable.. This variable can be displayed then...

Zeek

00100b
03-04-2004, 02:18 PM
Maybe you could word your questions more appropriately in the future.

Are you familiar with ADO and the use of the Connection and Recordset objects?

If not, then you may want to start with ADO Tutorial (http://www.visualbasicforum.com/showthread.php?threadid=66994).

If so, then once you have your recordset containing the field whose value you wish to display, the concept is the same as concatenating the string variable. The difference would be that you would reference the Value of the Field in the Recordset object.

robbielove
03-04-2004, 02:28 PM
I have the SQL statement and all made. I think to sort this out ill just show you the code that i have:

++++++++++ CODE +++++++++++++++++++

Private Sub cmdLoginButton_Click()

Dim sqlString As String

sqlString = "SELECT Bookmaker_Name FROM Bookmaker WHERE Bookmaker_No ='" & txtUsername.Text & "' AND Bookmaker_Password ='" & txtPassword.Text & "';"
cmd.CommandText = sqlString
cmd.Execute

rs.Open cmd, , adOpenStatic

If rs.EOF And rs.BOF Then
MsgBox "Please check your login/password"
Else
MsgBox ("Bookmaker: " & sqlString & "Thank You for logging in. Click Ok to continue.")
frmBookmakerLogin.Hide
frmBookmakerMain.Show
End If

End Sub

++++++++++++++++++++++++++++++++++

MiniMe
03-04-2004, 09:31 PM
Don't forget this...

rs.Open sqlString, adOpenStatic

MiniMe

MiniMe
03-04-2004, 09:36 PM
Or rather... forgive me I'm tired :P

strFile = "yourdb.mdb"

sqlString = "SELECT Bookmaker_Name FROM Bookmaker WHERE Bookmaker_No ='" & txtUsername.Text & "' AND Bookmaker_Password ='" & txtPassword.Text & "';"

cmd.ConnectionString = strFile 'opens the ADO connection and recordset
cmd.Provider = "Microsoft.Jet.OLEDB.4.0"
cmd.Open

rs.Open cmd, sqlString, adOpenStatic

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum