473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Access + VB6 recordset troubles

I have a database in Access 2003 (Access2000 file format). There are
two tables that are being used: Employees and Items. It is linked by
the Employee field so that one employee can have many items.

I have a VB6 application that is tied into this database using an
ADODB.Connection and uses two ADODB.Recordsets: rsEmployees and rsItems.
I can pull data from the DB into the app with both recordsets. But I
can only change data in rsItems and have the changes be made to the
database. rsEmployees loads data, but doesn't save any of the data I
change back to the database. Mainly I just want to use the Checkbox:
ChkSeeMe to save a check onto the checkbox in the Access Database. I
have included the code so that hopefully someone can check it out and
help me with this problem.
Thanks Much,
Ray

<BEGIN CODE>
Option Explicit
Private WithEvents cnMorris As ADODB.Connection
Private WithEvents rsEmployees As ADODB.Recordset
Private WithEvents rsItems As ADODB.Recordset
Dim mblnAddMode As Boolean
______________________
Private Sub Form_Load()

Dim strConnect As String
Dim strProvider As String
Dim strDataSource As String
strProvider = "Provider=Microsoft.Jet.OLEDB.4.0;"
strDataSource = "Data Source=\\Computer\Path\Inventory.mdb"
'The local or network share path to the Access Database
strConnect = strProvider & strDataSource

Set cnMorris = New ADODB.Connection
cnMorris.CursorLocation = adUseClient
cnMorris.Open strConnect
'Connect to the database

Set rsEmployees = New ADODB.Recordset
rsEmployees.CursorType = adOpenStatic
rsEmployees.CursorLocation = adUseClient
rsEmployees.LockType = adLockPessimistic
rsEmployees.ActiveConnection = cnMorris
rsEmployees.Source = "SELECT * FROM Employees WHERE Username = '" &
Environ$("Username") & "'"
'SQL to select all the employees that match the windows username of
the logged in user
rsEmployees.Open
'Opens the database and pulls all records from the SQL statement
into the recordset rsEmployees

Set rsItems = New ADODB.Recordset
rsItems.CursorType = adOpenStatic
rsItems.CursorLocation = adUseClient
rsItems.LockType = adLockPessimistic
rsItems.ActiveConnection = cnMorris
rsItems.Source = "SELECT * FROM Items WHERE Employee = '" &
rsEmployees!Employee & "' ORDER BY SIU"
'SQL to select all the Items that have the employee's name in that
record and order them by the SIU Tag #
rsItems.Open
'Opens the database and pulls all records from the SQL statement
into the recordset rsItems

LblPosition.Caption = " "

Call LoadDataInControls
'Loads data from Items table into form to view

End Sub
_______________________________
Private Sub LoadDataInControls()

If rsItems.BOF = True Or rsItems.EOF = True Then
Exit Sub
End If

LblEmployee.Caption = rsEmployees!Employee
TxtLast.Text = rsEmployees!LastName
If rsEmployees!SeeMe = True Then
ChkSeeMe.Value = 1
Else
ChkSeeMe.Value = 0
End If
LblSIU.Caption = rsItems!SIU
LblSerial.Caption = rsItems!Serial
LblDesc.Caption = rsItems!Description
LblItemNum.Caption = "Item " & rsItems.AbsolutePosition & " of " &
rsItems.RecordCount
LblRoom.Caption = rsItems!room
OptHas.Value = rsItems!Has
OptHasNot.Value = rsItems!HasNot

End Sub
_______________________________
Private Sub rsItems_MoveComplete(ByVal adReason As
ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As
ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)

If mblnAddMode = False Then
'If we are not in the add mode, load data in the controls.

Call LoadDataInControls
End If
End Sub
_______________________________
Private Sub BtnPrev_Click()

'Checks to see if OptHas or OptHasNot has been selected
If OptHas.Value = False And OptHasNot.Value = False Then
MsgBox ("You must select whether you Have or Do NOT Have this item")
Exit Sub
End If

Call RadioButton
Call ChkBox
LblPosition.Caption = " "
BtnNext.Enabled = True
If rsItems.BOF = False Then
rsItems.MovePrevious
If rsItems.BOF = True Then
rsItems.MoveFirst
BtnPrev.Enabled = False
LblPosition.Caption = "You are at the first item"
End If
Else
If rsItems.EOF Then
MsgBox ("There are no items for " & rsEmployees!Employee), ,
"Oops!"
Else
rsItems.MoveFirst
End If
End If

End Sub
_______________________________
Private Sub BtnNext_Click()

rsEmployees!LastName = TxtLast.Text

'Checks to see if OptHas or OptHasNot has been selected
If OptHas.Value = False And OptHasNot.Value = False Then
MsgBox ("You must select whether you Have or Do NOT Have this item")
Exit Sub
End If

Call RadioButton
Call ChkBox
LblPosition.Caption = " "
BtnPrev.Enabled = True
If rsItems.EOF = False Then
rsItems.MoveNext
If rsItems.EOF Then
rsItems.MoveLast
LblPosition.Caption = "You are at the last item"
BtnNext.Enabled = False
End If
Else
If rsItems.BOF Then
MsgBox ("There are no items for " & rsEmployees!Employee), ,
"Oops!"
Else
rsItems.MoveLast
End If
End If

End Sub
_______________________________
Private Sub ChkBox()

'Writes the SeeMe value to the database in the Employee table
If ChkSeeMe.Value = 1 Then
rsEmployees!SeeMe = True
Else
rsEmployees!SeeMe = False
End If

End Sub
_______________________________
Private Sub RadioButton()

'Writes the Has and HasNot values to the database in the Items table
If OptHas.Value = True Then
rsItems!Has = "True"
rsItems!HasNot = "False"
ElseIf OptHasNot.Value = True Then
rsItems!HasNot = "True"
rsItems!Has = "False"
End If

End Sub
_______________________________
Private Sub OptHasNot_GotFocus()
'When the Option Button for "I do NOT have this item." is clicked, this
box pops up and asks if they are sure.
Dim Sure
Sure = MsgBox("Are you sure that you do not have this item? Have you
looked everywhere?", vbYesNo, "Missing Item")
If Sure = vbNo Then
OptHasNot.Value = False
Else
OptHasNot.Value = True
End If

End Sub
_______________________________
Private Sub BtnExit_Click()

cnMorris.Close
Set cnMorris = Nothing
'Close the connection to the database
Unload Me
'Unload the form which exits the application
End Sub
<END CODE>
Nov 13 '05 #1
1 5890
Your problem is easily resolved by using the ADODB command object
instead of a recordset object for performing Updates, Deletes, and
Inserts. These are all action items. For Action items you want to
think in terms of the command object. For reads you can use the
recordset objects. With ADO.Net you can use a DataReader object for
reading; much nicer and easier to work with.

Here is a sample using the command object:

Dim cmd As New ADODB.Command
cmd.ActiveConnection =
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";Us er ID =;Data
Source=C:\somedir\yourmdb.mdb"

cmd.CommandType = adCmdText
cmd.CommandText = "Update tbl1 Set fld1 = 'test'"
cmd.Execute

cmd.CommandText = "Insert Into tbl1 (fld1, fld2, fld3) " _
& "Values('test1', 'test2', 'test3')
cmd.Execute

cmd.ActiveConnection.Close

Here I am assuming tbl1 contains all text fields. Thus, delimit with
single quotes "'". For numeric - no delimeters, for dates, use "#" the
pound sign.

HTH
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Josh Strickland | last post by:
I am attempting to create an Access database which uses forms to enter data. The issue I am having is returning the query results from the Stored Procedure back in to the Access Form. ...
2
by: Jim Pettway | last post by:
I am trying to run MS Access 97 on Windows ME and it continuously crashes (will not read Access data and then Windows locks up). The program runs fine on Windows 95 and Windows XP. Somewhere I...
4
by: JMCN | last post by:
object invalid or no longer set - confusion of the recordset in access 2003. i am currently converting from access 97 to access 2003. majority of the codes converted over perfectly fine, though...
3
by: alex_peri | last post by:
Hello All, I am having problems with sorting a recordset by fields in Access. I have a table with three columns called ID, SNo and Time and would like to sort the records by Time. I would like to...
0
by: jayohare | last post by:
Hello, I have code within my DB application to process credit cards through authorize.net. Ive been using the same code for several years without a problem. I have an order entry computer and...
2
by: ARC | last post by:
Just curious if anyone is having issues with Acc 2007 once the number of objects and complexity increases? I have a fairly large app, with many linked tables, 100's of forms, queries, reports, and...
0
by: Yarik | last post by:
Hello, Here is a sample (and very simple) code that binds an Access 2003 form to a fabricated ADO recordset: ' Create recordset... Dim rs As ADODB.Recordset: Set rs = New ADODB.Recordset '...
6
by: jsacrey | last post by:
Hello everybody, I've got a bit of a situation that I could use some guidance with if possible. I work for an auditing firm where my users audit electronic shipping data for customers to see if...
2
by: curran.george | last post by:
'add one textbox to form1 with Control Source property = ID 'copy/paste the form_load code below: 'Then open the form and then attempt to sort the datasheet 'crashes 2003, error 3450 Access 2007 -...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.