Hi guys,
I'm having some trouble with linking in an Access 2003 database which i have created into Visual Basic 6.
I've created a game, so far i have it successfully writing the username to the database, but i cannot for the life of me figure out how to get it to also write the users scores to the database (win, lose and played).
These values are stored and updated by the program each time the user plays a game and I want to be able to write the value into the database under the current username.
I am new to VB so please dont assume i know anything quite advanced.
I have so far come up with the following code:
This section seems to be functioning fine as the username is being writen to the database.
This is so far what I've come up with, this should add 1 to the "Hints" field each time the user select the hint button.
Once I get the correct syntax for this section i will extend it to keep track of wins/loses/played aswell.
I have looked extensively elsewhere for snippets of code to guide me in the right direction but have found nothing of use, I hope you will be able to assist me :)
Many thanks,
Stephen
I'm having some trouble with linking in an Access 2003 database which i have created into Visual Basic 6.
I've created a game, so far i have it successfully writing the username to the database, but i cannot for the life of me figure out how to get it to also write the users scores to the database (win, lose and played).
These values are stored and updated by the program each time the user plays a game and I want to be able to write the value into the database under the current username.
I am new to VB so please dont assume i know anything quite advanced.
I have so far come up with the following code:
Code:
Dim cn As Connection
Public Sub Form_Load()
Set cn = New Connection
Dim Rs As New Recordset
ChDir (App.Path)
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Hangman.mdb"
Rs.Open "[user]", cn, adOpenKeyset
Rs.MoveFirst
strUsername = InputBox("Please enter a username.", "UserName", Rs.Fields("Username"))
If strUsername = "" Then
Rs.Close
Set Rs = Nothing
Unload Me
Exit Sub
End If
Rs.Find "Username = '" & strUsername & "'"
If Rs.EOF Or Rs.BOF Then
cn.Execute ("INSERT INTO [user] (Username) VALUES ('" & strUsername & "')")
Rs.Requery
Rs.Find "Username = '" & strUsername & "'"
End If
Rs.Close
Set Rs = Nothing
End Sub
Code:
Private Sub cmdHint_Click()
Set cn = New Connection
Dim Rs As New Recordset
ChDir (App.Path)
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Hangman.mdb"
iHints = iHints + 1
Rs.Filter = "Username ='" & strUsername & "'"
cn.Execute ("INSERT INTO [user] (Hints) VALUES ('" & iHints & "')")
End Sub
Once I get the correct syntax for this section i will extend it to keep track of wins/loses/played aswell.
I have looked extensively elsewhere for snippets of code to guide me in the right direction but have found nothing of use, I hope you will be able to assist me :)
Many thanks,
Stephen
Comment