473,397 Members | 1,950 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,397 software developers and data experts.

VB Code working but only when I step through

Hi Folks
Iam a newbee to the forum and am having a few problems with Access. Have any of you seen this before in Access 2003.

I have two subforms based on separate queries. I use a mixture of SQL to manipulate the tables Iam dealing with...no heres the strange part. All my code works perfectly fine and does exactly what it should do when a breakpoint it and step thorugh it line by line. I can see the changes happening in the forms as I step through...However when I run it normally without seeing the step throughs it wont update the forms on the refresh event. Its as though it skips it out. I have tried everythng now but cant see why it would work fine in step through mode and not normally. Any ideas or help would be much appreciated?

I have compacted and repaired the database thinking it could be something to do with that but still does the same

Thanks in advance
EasyGeeza
Nov 16 '07 #1
3 2927
FishVal
2,653 Expert 2GB
Hi, EasyGeeza.

Posting the code would certainly help us to figure out how it may be fixed.

Regards,
Fish
Nov 16 '07 #2
Hi, EasyGeeza.
Sorry guys code as follows


Posting the code would certainly help us to figure out how it may be fixed.

Regards,
Fish
Private Sub cmdRemoveFromHire_Click()
'DB connection and Recordset objects
Dim rsItemToMove As ADODB.Recordset


Set DBConn = New ADODB.Connection
Set rsItemToMove = New ADODB.Recordset

' vars for manipulation
Dim LineSelection() As Boolean
Dim CarSelector
Dim ContactName As String
Dim CarMake As String
Dim CarModel As String
Dim CarID As Integer
Dim ContactID As Integer
Dim test As String
If Me.subfrmCarsField.Form.Dirty Then
DoCmd.RunCommand acCmdSaveRecord
End If

' SQL command obect and instance
Dim SQLCommand As ADODB.Command
Set SQLCommand = New ADODB.Command

strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & CurrentProject.Path & CurrentProject.Connection

' database connection patch and source detail declared globally
DBConn.Open strConnection 'open DB connection using path

Me.subfrmCarsField.Form.RecordsetClone.MoveFirst 'clone the subforms query results from form selection
'into cloned recordset and move to first position

' loop through rows returned in subform cloned record set and pass to rsSubFormRows RS
While Me.subfrmCarsField.Form.RecordsetClone.EOF = False ' while recordsetclone not at the end of the file
CarID = Me.subfrmCarsField.Form.RecordsetClone("CarID")
ContactID = Me.subfrmCarsField.Form.RecordsetClone("ContactID" )
CarSelector = Me.subfrmCarsField.Form.RecordsetClone("CarSeletor ")
If CarSelector = True Then ' if row selected from form
SQLCommand.ActiveConnection = DBConn ' assign the command object to the relevant connection
'you are about to update/execute so it knows which
' DB connection its dealing with
' put the command SQL string into the object ready for execution / update of table
SQLCommand.CommandText = "UPDATE tblCars SET ContactID = 0 WHERE CarID=" & CarID ' remove person from car
SQLCommand.Execute 'perform above SQL statement
SQLCommand.CommandText = "UPDATE tblCars SET CarSeletor = False" 'reset tickbok
SQLCommand.Execute 'perform above SQL statement


End If
Me.subfrmCarsField.Form.RecordsetClone.MoveNext
Wend

subfrmCarsField.Requery 'refreshes data (from a qryCars) in subform using primary key ContactID feild
subfrmCarsOffHireField.Requery
'refresh both subforms query after table alterations above



End Sub
Nov 19 '07 #3
FishVal
2,653 Expert 2GB
Well. The code is not optimal and not always reliable.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdRemoveFromHire_Click()
  2. 'DB connection and Recordset objects
  3. Dim rsItemToMove As ADODB.Recordset
  4.  
  5.  
  6. Set DBConn = New ADODB.Connection
  7. Set rsItemToMove = New ADODB.Recordset
  8.  
  9. ' vars for manipulation
  10. Dim LineSelection() As Boolean
  11. Dim CarSelector
  12. Dim ContactName As String
  13. Dim CarMake As String
  14. Dim CarModel As String
  15. Dim CarID As Integer
  16. Dim ContactID As Integer
  17. Dim test As String
  18.  
  19.  
  20.  If Me.subfrmCarsField.Form.Dirty Then
  21.   DoCmd.RunCommand acCmdSaveRecord
  22.  End If
  23.  
  24. ' SQL command obect and instance
  25. Dim SQLCommand As ADODB.Command
  26. Set SQLCommand = New ADODB.Command
  27.  
  28. strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  29. "Data Source=" & CurrentProject.Path & CurrentProject.Connection
  30.  
  31. ' database connection patch and source detail declared globally
  32. DBConn.Open strConnection 'open DB connection using path
  33.  
  34.  
There is no need to open separate ADODB.Connection as soon as db already has connection via Jet.OLEDB provider. The Connection object is accessible via CurrentProject.Connection property. Moreover, if you will try to run the code having not saved design changes it is likely to fail with "DB locked" error.
There is definitely no need to open separate or use opened one ADODB.Connection to execute SQL command only. DoCmd.RunSQL will be quite enough.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Me.subfrmCarsField.Form.RecordsetClone.MoveFirst 'clone the subforms query results from form selection
  3.                                                  'into cloned recordset and move to first position
  4.  
  5. ' loop through rows returned in subform cloned record set and pass to rsSubFormRows RS
  6. While Me.subfrmCarsField.Form.RecordsetClone.EOF = False ' while recordsetclone not at the end of the file
  7.  CarID = Me.subfrmCarsField.Form.RecordsetClone("CarID")
  8.  ContactID = Me.subfrmCarsField.Form.RecordsetClone("ContactID")
  9.  CarSelector = Me.subfrmCarsField.Form.RecordsetClone("CarSeletor")
  10.    If CarSelector = True Then ' if row selected from form
  11.     SQLCommand.ActiveConnection = DBConn ' assign the command object to the relevant connection
  12.                                          'you are about to update/execute so it knows which
  13.                                          ' DB connection its dealing with
  14.     ' put the command SQL string into the object ready for execution / update of table
  15.     SQLCommand.CommandText = "UPDATE tblCars SET ContactID = 0 WHERE CarID=" & CarID ' remove person from car
  16.     SQLCommand.Execute 'perform above SQL statement
  17.     SQLCommand.CommandText = "UPDATE tblCars SET CarSeletor = False" 'reset tickbok
  18.     SQLCommand.Execute 'perform above SQL statement
  19.  
  20.  
The logic of code is not clear. First SQL statement sets ContactID to 0 for car(s) having particular CarID. Second SQL statement clears CarSelector field in all records of tblCars (????).

Expand|Select|Wrap|Line Numbers
  1.    End If
  2.  Me.subfrmCarsField.Form.RecordsetClone.MoveNext
  3. Wend
  4.  
  5. subfrmCarsField.Requery 'refreshes data (from a qryCars) in subform using primary key ContactID feild
  6. subfrmCarsOffHireField.Requery
  7. 'refresh both subforms query after table alterations above
  8.  
  9.  
  10.  
  11. End Sub
  12.  
Anyway, it seems that the same may be achieved with a several SQL statements only. Could you post MetaData for all relevant datasets. Here is an example of how to post table MetaData :
Table Name=tblStudent
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. StudentID; AutoNumber; PK
  3. Family; String; FK
  4. Name; String
  5. University; String; FK
  6. Mark; Numeric
  7. LastAttendance; Date/Time
Particulary I mean tblCars and qryCars.
Nov 19 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
6
by: Mario T. Lanza | last post by:
Greetings, I don't know about you guys but on many occasions I've asked myself whether or not someone else has solved a particular programming issue -- whether or not they developed a clever...
67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
6
by: Mark Reed | last post by:
Hi all, I am trying to learn a little about programming (I know next to nothing so far) and have found some code which hides the toolbars. However, this bit of code is a little too effective and...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
2
by: Robert Iver | last post by:
Hello fellow developers, I'm hoping someone out there can steer me down the right path with this little conundrum I have, because I am getting frustrated more and more by the minute. I have a...
13
by: Hendrik van Rooyen | last post by:
Hi, I would like to do the following as one atomic operation: 1) Append an item to a list 2) Set a Boolean indicator It would be almost like getting and holding the GIL, to prevent a...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.