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

Visual Basic code only works sometimes in access

18
This is my first time not sure whats needed this is XP office

this is the code i`m trying to run i have tried on close and command buttons
i don`t even get an error code just does not run

Expand|Select|Wrap|Line Numbers
  1. Dim dbsMedicalSupplies As Database
  2.     Dim rstStock As Recordset
  3.     Dim strToOrder As String
  4.     Dim strExtraOrder As String
  5.  
  6.     Set dbsMedicalSupplies = OpenDatabase("x:\MedicalSupplies\MedicalSupplies.mdb")
  7.     Set rstStock = _
  8.         dbsMedicalSupplies.OpenRecordset("Stock", _
  9.         dbOpenDynaset)
  10.         With rstStock
  11.  
  12.     .MoveFirst
  13.     Do While Not .EOF
  14.         .Edit
  15.         !ToOrder = !ToOrder + !ExtraOrder
  16.         !ExtraOrder = 0
  17.         .Update
  18.         .MoveNext
  19.     Loop
  20.     End With
  21.  
  22.     rstStock.Close
  23.     dbsMedicalSupplies.Close
  24.  
  25. End Sub
thank you for your time
cheers Powelly
Dec 13 '06 #1
3 1721
MMcCarthy
14,534 Expert Mod 8TB
Firstly there is no indication of the sub or function command line at the beginning of this code. For the moment I'll assume a command button called cmdOrderStock. I've also reset the Recordset variable type to DAO.Recordset because if the ADO library is also referenced this can cause confusion.

Expand|Select|Wrap|Line Numbers
  1.  Private Sub cmdOrderStock_Click()
  2. Dim dbsMedicalSupplies As Database
  3.     Dim rstStock As DAO.Recordset
  4.     Dim strToOrder As String
  5.     Dim strExtraOrder As String
  6.  
Secondly if the database you are referencing is the same database you are working on then you don't need the full path. Change it as follows otherwise leave it as it is.

Expand|Select|Wrap|Line Numbers
  1.     Set dbsMedicalSupplies =CurrentDB
  2.     Set rstStock = dbsMedicalSupplies.OpenRecordset("Stock",dbOpenDynaset)
  3.  
  4.         With rstStock
  5.  
  6.         .MoveFirst
  7.    Do While Not .EOF
  8.       .Edit
  9.       !ToOrder = !ToOrder + !ExtraOrder
  10.       !ExtraOrder = 0
  11.               .Update
  12.       .MoveNext
  13.    Loop
  14.     End With
  15.  
Lastly you want to close the recordset but also set it to nothing and the same for the database. If the database is your current database then you don't want to close it.

Expand|Select|Wrap|Line Numbers
  1.     rstStock.Close
  2. Set rstStock = Nothing
  3. 'dbsMedicalSupplies.Close
  4. Set dbsMedicalSupplies = Nothing
  5.  
  6. End Sub
  7.  
Mary
Dec 13 '06 #2
powelly
18
Firstly there is no indication of the sub or function command line at the beginning of this code. For the moment I'll assume a command button called cmdOrderStock. I've also reset the Recordset variable type to DAO.Recordset because if the ADO library is also referenced this can cause confusion.

Expand|Select|Wrap|Line Numbers
  1.  Private Sub cmdOrderStock_Click()
  2. Dim dbsMedicalSupplies As Database
  3.     Dim rstStock As DAO.Recordset
  4.     Dim strToOrder As String
  5.     Dim strExtraOrder As String
  6.  
Secondly if the database you are referencing is the same database you are working on then you don't need the full path. Change it as follows otherwise leave it as it is.

Expand|Select|Wrap|Line Numbers
  1.     Set dbsMedicalSupplies =CurrentDB
  2.     Set rstStock = dbsMedicalSupplies.OpenRecordset("Stock",dbOpenDynaset)
  3.  
  4.         With rstStock
  5.  
  6.         .MoveFirst
  7.    Do While Not .EOF
  8.       .Edit
  9.       !ToOrder = !ToOrder + !ExtraOrder
  10.       !ExtraOrder = 0
  11.               .Update
  12.       .MoveNext
  13.    Loop
  14.     End With
  15.  
Lastly you want to close the recordset but also set it to nothing and the same for the database. If the database is your current database then you don't want to close it.

Expand|Select|Wrap|Line Numbers
  1.     rstStock.Close
  2. Set rstStock = Nothing
  3. 'dbsMedicalSupplies.Close
  4. Set dbsMedicalSupplies = Nothing
  5.  
  6. End Sub
  7.  
Mary
Powelly[/quote]

Thank You mary it`s working like it should
These are he two thing that fixed
[code]
Dim rstStock As DAO.Recordset
&
[code]

rstStock.Close
Set rstStock = Nothing
'dbsMedicalSupplies.Close
Set dbsMedicalSupplies = Nothing

Thanks again

Cheers Powelly
Dec 20 '06 #3
MMcCarthy
14,534 Expert Mod 8TB
You're Welcome

Mary
Dec 20 '06 #4

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

Similar topics

5
by: K. Shier | last post by:
when attempting to edit code in a class file, i see the bug "Visual Basic ..NET compiler is unable to recover from the following error: System Error &Hc0000005&(Visual Basic internal compiler...
4
by: Corepaul | last post by:
I am a beginner, using Access 2000. I am having difficulty with the Visual Basic Help. Specifically, using the Index tab, when I enter "OpenRecordset" in the keyword field and click the Search...
10
by: Steve | last post by:
I am trying to create a DLL in Visual Studio 2005-Visual Basic that contains custom functions. I believe I need to use COM interop to allow VBA code in Excel 2002 to access it. I've studied...
3
by: RichardJB | last post by:
Hi, I am using visual basic in access 2003 and am having a problem with sorting tables which I can't seem to find a solution to, and was hoping that someone might be able to help. I have a...
11
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I have seen the terms Visual Basic 2005 and VB.NET. It seems that sometimes they seem to be referring to the same thing but sometimes they are not. I also run into terms like VB9 and VB10.
0
by: giladbarner | last post by:
Hello everyone, I have office 2003 Professional, and I work in Access's Visual Basic Editor. Sometimes after opening the "Microsoft Visual Basic Help" window by standing on a function in the...
1
by: =?Utf-8?B?QW5keSBTLg==?= | last post by:
I have an application written in Visual Basic .NET in Visual Studio 2005 that runs on a server and simply uses the filesystem.copydirectory to backup folders from my pc to a server. The problem I...
1
by: Ronm | last post by:
Hey Guys, I have a problem which has been driving me crazy for the last days. I'm working on a small project involving: Visual Basic Acces Database ASP and adobe/macromedia Flash,
11
by: research | last post by:
Hi, I'm using Visual Basic 2005 Express Edition to develop small tools in relation with our applications and I'm facing a problem using the interface. It sometimes happens that the design...
6
by: Vince | last post by:
Hello all, I am using Visual Basic to open a saved query and then save information in the query to an array for later use. The problem is that the same query shows different results when opened...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.