473,545 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Connectio n and uses two ADODB.Recordset s: 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.Connectio n
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=Micro soft.Jet.OLEDB. 4.0;"
strDataSource = "Data Source=\\Comput er\Path\Invento ry.mdb"
'The local or network share path to the Access Database
strConnect = strProvider & strDataSource

Set cnMorris = New ADODB.Connectio n
cnMorris.Cursor Location = adUseClient
cnMorris.Open strConnect
'Connect to the database

Set rsEmployees = New ADODB.Recordset
rsEmployees.Cur sorType = adOpenStatic
rsEmployees.Cur sorLocation = adUseClient
rsEmployees.Loc kType = adLockPessimist ic
rsEmployees.Act iveConnection = cnMorris
rsEmployees.Sou rce = "SELECT * FROM Employees WHERE Username = '" &
Environ$("Usern ame") & "'"
'SQL to select all the employees that match the windows username of
the logged in user
rsEmployees.Ope n
'Opens the database and pulls all records from the SQL statement
into the recordset rsEmployees

Set rsItems = New ADODB.Recordset
rsItems.CursorT ype = adOpenStatic
rsItems.CursorL ocation = adUseClient
rsItems.LockTyp e = adLockPessimist ic
rsItems.ActiveC onnection = cnMorris
rsItems.Source = "SELECT * FROM Items WHERE Employee = '" &
rsEmployees!Emp loyee & "' 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.Cap tion = " "

Call LoadDataInContr ols
'Loads data from Items table into form to view

End Sub
_______________ _______________ _
Private Sub LoadDataInContr ols()

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

LblEmployee.Cap tion = rsEmployees!Emp loyee
TxtLast.Text = rsEmployees!Las tName
If rsEmployees!See Me = True Then
ChkSeeMe.Value = 1
Else
ChkSeeMe.Value = 0
End If
LblSIU.Caption = rsItems!SIU
LblSerial.Capti on = rsItems!Serial
LblDesc.Caption = rsItems!Descrip tion
LblItemNum.Capt ion = "Item " & rsItems.Absolut ePosition & " of " &
rsItems.RecordC ount
LblRoom.Caption = rsItems!room
OptHas.Value = rsItems!Has
OptHasNot.Value = rsItems!HasNot

End Sub
_______________ _______________ _
Private Sub rsItems_MoveCom plete(ByVal adReason As
ADODB.EventReas onEnum, ByVal pError As ADODB.Error, adStatus As
ADODB.EventStat usEnum, ByVal pRecordset As ADODB.Recordset )

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

Call LoadDataInContr ols
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.Cap tion = " "
BtnNext.Enabled = True
If rsItems.BOF = False Then
rsItems.MovePre vious
If rsItems.BOF = True Then
rsItems.MoveFir st
BtnPrev.Enabled = False
LblPosition.Cap tion = "You are at the first item"
End If
Else
If rsItems.EOF Then
MsgBox ("There are no items for " & rsEmployees!Emp loyee), ,
"Oops!"
Else
rsItems.MoveFir st
End If
End If

End Sub
_______________ _______________ _
Private Sub BtnNext_Click()

rsEmployees!Las tName = 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.Cap tion = " "
BtnPrev.Enabled = True
If rsItems.EOF = False Then
rsItems.MoveNex t
If rsItems.EOF Then
rsItems.MoveLas t
LblPosition.Cap tion = "You are at the last item"
BtnNext.Enabled = False
End If
Else
If rsItems.BOF Then
MsgBox ("There are no items for " & rsEmployees!Emp loyee), ,
"Oops!"
Else
rsItems.MoveLas t
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!See Me = True
Else
rsEmployees!See Me = 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_GotFo cus()
'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 5901
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.ActiveConne ction =
"Provider=Micro soft.Jet.OLEDB. 4.0;Password="" "";User ID =;Data
Source=C:\somed ir\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.ActiveConne ction.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
11674
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. tCetecM1CUST (SQL Table that contains the Customer Information) tAccountingDetail (SQL Table that contains the information in the form) frmAccountingEntry...
2
1881
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 read that Windows ME had problems with Access 97. Has anyone had any experience with this setup? Please give me some help with this situation. Jim...
4
2535
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 my recordset did not. i read from pasts posts that some references will not convert. so i tried to change the dao 3.51 reference to dao 3.6 in...
3
35431
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 sort them in the actual database and not just Order them with SQL. I have included the code I wrote below. Please bear in mind that I am very new to...
0
2320
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 after reinstalling Win XP, we used Office/Access 2003. When we try to process CC's we get a debug screen and Access itself crashes. However, the code...
2
3780
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 lots of vba code. I'm nearly finished with re-doing my app in access 2007, and just imported an add-in program, which has added even more forms,...
0
3116
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 ' Append one or more fields... Call rs.Fields.Append("Number", adInteger)
6
2664
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 they've been overcharged for shipments by truck and rail carriers. 99.9% of the time, one of our auditors needs to see all data sent by a...
2
3510
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 - I can't find much info on this... - Can someone explain what's happening and how to fix this? Private Sub Form_Load() '2008-01-11 Dim rsx As...
0
7410
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7668
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7773
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5984
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5343
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4960
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3466
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.