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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL access thorugh VB6

Status
Not open for further replies.

1gbram

Technical User
Jul 1, 2006
69
GB
Hi all,
I'm trying to access a MySQL database through VB6, and iv used a script I found on google. It says to access colums using " ! " followed by the column name, for example for the column 'username' use:

variable = !username

I am trying to incorporate this in to a function, where the column might change, how would I access different columns depending on variables?
 
Use something like this:

variable = rs("UserName")

or

variable = rs(MyVariableWithTheFieldName)

Where rs is your recordset.
 
The bang (!) notation is used to identify a field in a recordset. For example
Code:
myValue = rs![Field5]
Selects the field named "Field5" in the current record in the recordset "rs".

You can use the notation that you presented in conjunction with a WITH statement
Code:
With rs
    myValue = ![Field5]
End With
and that does the same thing as the first example.

I always use square brackets around the field name. They are not required in all cases but they are required if the field name contains spaces or if the field name is a reserved word.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top