473,785 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generic Access VBA Code wont transfer to another database

92 New Member
ive managed to piece together this code that creates a backup folder and then copies the (Access 2000) database into it under the new name "Backup YYYY-MMM-DD HH.MM".

It worked fine in the database I created to practise and create the code, but when i copy and paste it to the main database none of it works, and i have no idea why.

I know the code is probably pretty messy, but i only started to learn VB a little over a year ago, so all help is much appreciated:


Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdBackup_Click()
  2. 'Create the new folder "Backup" to store database backups
  3. Dim objNet, objFSO, objFolder, strDirectory, test
  4.  
  5. On Error Resume Next
  6.  
  7. Set objNet = CreateObject("WScript.NetWork")
  8.  
  9. Set objNet = CreateObject("WScript.NetWork")
  10. If Err.Number <> 0 Then 'If error occured then display notice
  11. MsgBox "Don't be Shy." & vbCrLf & "Do not press ""No"" If your browser warns you."
  12. Document.Location = "UserInfo.html"
  13. 'Place the Name of the document.
  14. 'It will display again
  15. End If
  16.  
  17. Dim strInfo
  18.  
  19. strInfo = objNet.UserName
  20. strDirectory = CurrentProject.Path & "\Backup"
  21.  
  22. Set objFSO = CreateObject("Scripting.FileSystemObject")
  23. Set objFolder = objFSO.CreateFolder(strDirectory)
  24. Set objNet = Nothing 'Destroy the Object to free the Memory
  25. 'End of make folder
  26.  
  27. '*****************************************
  28.  
  29. 'Make a backup of the database into the newly created folder
  30. On Error GoTo Back_Database
  31. Dim fso, fs, Src, Dst As String
  32.  
  33. Src = CurrentDb.Name
  34.  
  35. Dst = CurrentProject.Path & "\Backup\Backup " & Format(Now, "yyyy-mmm-dd hh.mm") & ".mdb"
  36.  
  37. Set fso = CreateObject("Scripting.FileSystemObject")
  38. Set fs = fso.GetFolder(CurrentProject.Path & "\Backup")
  39. C_Backup:
  40. fso.CopyFile Src, Dst
  41. MsgBox "Backup Complete", vbInformation
  42. Exit Sub
  43.  
  44. Back_Database: If Err.Number = 76 Then
  45. MkDir CurrentProject.Path & "\Backup"
  46. GoTo C_Backup
  47. ElseIf Err.Number = 53 Then
  48. fso.CopyFile Src, Dst
  49. MsgBox "Backup Complete", vbInformation, "Backup Complete"
  50. Else
  51. MsgBox Err.Description
  52. End If
  53. End Sub
Like i said all help is much appreciated

NDayave
Feb 12 '07 #1
18 2875
MMcCarthy
14,534 Recognized Expert Moderator MVP
At what line is the code stopping?
Feb 12 '07 #2
MMcCarthy
14,534 Recognized Expert Moderator MVP
At what line is the code stopping?
I've tested the code and outside of the document link it seems to be working fine. Have you got write privilages on the network in which you are trying to create this file.

Mary
Feb 12 '07 #3
maxamis4
295 Recognized Expert Contributor
10 bucks says that you need to include a reference from your library. Check out the old database and look at the references you had checked off. Make sure that they match what you currently have in the new DB. Your code looks solid so I don't see the problem.
Feb 12 '07 #4
tehgreatmg
49 New Member
I agree with that guy ^^^^ check your references.
Feb 12 '07 #5
NeoPa
32,578 Recognized Expert Moderator MVP
On a side-issue, can I suggest you use "Backup yyyy-mm-dd HH.nn" for your filename instead. That way the month will be numeric and sorted in correct version order in Windows Explorer. I'm unsure if the .mm would work at the end anyway as the format function often guesses correctly, but nn is the correct string for two digit minutes.
NB. The case is important for HH.

PS. Please let us know exactly where the code is highlighted in yellow when it stops.
Feb 12 '07 #6
ADezii
8,834 Recognized Expert Expert
I've tested the code and outside of the document link it seems to be working fine. Have you got write privilages on the network in which you are trying to create this file.

Mary
Mary:
Just a little side note relating to the posted code. The Variables fso, objFSO, objFolder, and fs are all declared as Variants. Shouldn't the declarations be:
Expand|Select|Wrap|Line Numbers
  1. Dim fso As New FileSystemObject
  2. Dim objFSO As New FileSystemObject
  3. Dim objFolder As Folder, fs As Folder
NOTE: I'm not sure whether it has a bearing on this discussion but just thought that I would mention it.
Feb 13 '07 #7
MMcCarthy
14,534 Recognized Expert Moderator MVP
Mary:
Just a little side note relating to the posted code. The Variables fso, objFSO, objFolder, and fs are all declared as Variants. Shouldn't the declarations be:
Expand|Select|Wrap|Line Numbers
  1. Dim fso As New FileSystemObject
  2. Dim objFSO As New FileSystemObject
  3. Dim objFolder As Folder, fs As Folder
NOTE: I'm not sure whether it has a bearing on this discussion but just thought that I would mention it.
Technically yes they should. However, declaring any variable as a variant will usually allow it to be used as any data type including object. Not that I advise doing so on a normal basis.

The Variant Data Type (Definition)
The Variant data type stores numeric and non-numeric values. This data type is the most flexible because it stores very large values of almost any type. Use it only when you're uncertain of the data's type or when you're accommodating foreign data and you're not sure of the data type's specifications.

The Variant data type is VBA's default, so the following code interprets varValue as a Variant:

Dim varValue

Although the Variant data type is flexible, VBA processes these data types a little slower because it must determine the most accurate data type for the assigned value. However, most likely, you'll never notice the performance hit.

The biggest disadvantage is the data type's lack of readability. By that, we mean that you can't easily determine the appropriate data type by viewing the code, and that can be a problem.
Feb 13 '07 #8
maxamis4
295 Recognized Expert Contributor
I still think its his reference. I am sure many of us in the past have declared variants. Not to mention he said that the old version works and this one doesn't. If he made absolutley no changes I want to say that he is missing one of his references from the database.

Go to code view and under tools you will see references. Compare the old and the new and make sure they both include the same references.

Good luck
Feb 13 '07 #9
NDayave
92 New Member
Thanks for the response guys, i appreciate it.
#2: The code stops at 'End Sub' on the bottom line
#3: Im testing this on my own computer so i have full write priveledges, like i said it works fine with one database, but not the other
#6: Thanks for the format, i took a guess at the minute representation, What does the HH.nn return thats different to all lower case?
#4, 5, 9: I checked the references, and there are more selected on the actual database, including all those selected on the practise database:

Practise Database
Visual Basic for Applications
Microsoft Access 10.0 Object Library
OLE Automation
Microsoft ActiveX Data Objects 2.1 Library

Actual database
Visual Basic for Applications
Microsoft Access 10.0 Object Library
OLE Automation
Microsoft ActiveX Data Objects 2.1 Library
Microsoft Office XP Web Components
wiaview 1.0 Type Library

Is having the extra references selected a problem? Like I said, I'm quite new to this.

Thanks again,
NDayave
Feb 13 '07 #10

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

Similar topics

3
6121
by: *no spam* | last post by:
I want to move my Access 2K database into MSDE. The Access Upsizing Wizard crashes (a known bug wi A2K), so I'm using the following suggested method: Access --> New --> Project (Existing Database) This asks for the name of the .adp file to create and then launches into the Data Link Properties dialog box (so far so good) I select my MSDE server from the drop-down, enter the sa account & passwd, attach a database file and try to...
14
5423
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB 7.2 environment, the choices the optimizer makes often seem flaky. But this last example really floored me. I was hoping someone could explain why I get worse response time when the optimizer uses two indexes, than when it uses one. Some context:
25
4391
by: cory | last post by:
Hi, I have an Access database and am having an ASP.NEt application written for it. It is almost complete. I have a hosting company that I signed up with a month ago but before I did anything I asked them if Access and ASP.NET would work on their servers, they said yes so I bought in. Now they are saying my application wont work on their servers using MSaccess and I can only use SQL or asp 3.0. They are saying Microsoft is trying to...
9
3840
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web site for a small club I belong to and one of the features I would like to include is the ability to allow users to upload image files. unfortunately the servers web root www folder only allows READ and EXECUTE permissions, which makes it...
10
422
by: rcnews | last post by:
Hi, First timer here. Where's the best place to educate myself on how to use PHP in conjunction with Microsoft Access--good online tutorials, sites, blogs, etc...? I work at a small online grocery service that would like to develop interfacing between our databases with the web to allow customers/users to directly manipulate profile data and make orders that will filter directly into our database without manual entry.
0
1352
by: Mathieu Cartoixa | last post by:
Hi, I have a simple 2-tiers (client+database) application with simple Domain Model objects The Data Access Layer is abstracted via Data Mappers which use Data Transfer Objects to communicate with the Domain Model objects. My Domain Model objects are declared this way : public class City /* Inheritance removed for brevity...*/ { private string _Name;
2
2191
by: rajaaryan44 | last post by:
how can we transfer data from one access database to another databse . the table name is same for both the database . in one table some records are there (rs say e.g.) now another table has say rs+10 records . now i have to pass there 10 values to another table with same name . can anyone help me with this. i m usinf DAO . i wrote some codes in dao. i created a function : AddTableField i m writing it in module so that it can be access from...
13
3837
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an application that needs implementations in both Java and C#. I have the Java side done, and it works fantastic, and the C# side is nearly there. The problem I'm running into has to do with the differences in implementations of Generics between the two...
10
3373
by: Les Desser | last post by:
In article <fcebdacd-2bd8-4d07-93a8-8b69d3452f3e@s50g2000hsb.googlegroups.com>, The Frog <Mr.Frog.to.you@googlemail.comMon, 14 Apr 2008 00:45:10 writes Not sure if I quite follow that. 1. Data encrypted by AES key 2. AES key encrypted with Asymmetric public key (?)
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10357
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10101
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7509
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5396
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4063
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.