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

Generic Access VBA Code wont transfer to another database

92
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 2842
MMcCarthy
14,534 Expert Mod 8TB
At what line is the code stopping?
Feb 12 '07 #2
MMcCarthy
14,534 Expert Mod 8TB
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 Expert 100+
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
I agree with that guy ^^^^ check your references.
Feb 12 '07 #5
NeoPa
32,556 Expert Mod 16PB
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 Expert 8TB
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 Expert Mod 8TB
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 Expert 100+
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
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
NDayave
92
I unchecked the extra references on the actual database:
Microsoft Office XP Web Components
wiaview 1.0 Type Library

and it worked fine, thanks a lot.

Will having these two references unchecked have any negative consequences on the database though?

Thanks again,
NDayave
Feb 13 '07 #11
NeoPa
32,556 Expert Mod 16PB
This may sound like a lame answer, but "Only if your database is using anything provided by these libraries."
There shouldn't be anything standard affected by losing these two though I don't think.
Feb 13 '07 #12
maxamis4
295 Expert 100+
It can be, what references do is import built in functions that allow Access to communicate to other devices. I would match them up identically and see what results you get.
Feb 13 '07 #13
NDayave
92
With regard to the references, what determines which are selected and which aren't? Would there be any reason for the extra references to be checked in the actual database, or is it just a default setting?
Feb 13 '07 #14
MMcCarthy
14,534 Expert Mod 8TB
With regard to the references, what determines which are selected and which aren't? Would there be any reason for the extra references to be checked in the actual database, or is it just a default setting?
It's not a default setting only the first four are. The others are checked so that they can be used by the designer. Run the compiler and see if any errors pop up since you removed these references.

Mary
Feb 13 '07 #15
NDayave
92
I went into the code window => Debug => Compile Booking System

im guessing thats what you meant, there was a loading bar visible very briefly on the toolbar and then nothing else happened and now i cant compile again. Would i be right in thinking this means there are no problems?
Feb 13 '07 #16
MMcCarthy
14,534 Expert Mod 8TB
I went into the code window => Debug => Compile Booking System

im guessing thats what you meant, there was a loading bar visible very briefly on the toolbar and then nothing else happened and now i cant compile again. Would i be right in thinking this means there are no problems?
That would be my interpretation.

As a test, type could something and then delete it, the compiler should reset.

Mary
Feb 13 '07 #17
NDayave
92
That would be my interpretation.

As a test, type could something and then delete it, the compiler should reset.

Mary

Yeah it reset the compiler and again nothing but a glimpse of the loading bar and not being able to compile till something is changed again.

Thanks for that, appreciated

NDayave
Feb 13 '07 #18
NeoPa
32,556 Expert Mod 16PB
I went into the code window => Debug => Compile Booking System

im guessing thats what you meant, there was a loading bar visible very briefly on the toolbar and then nothing else happened and now i cant compile again. Would i be right in thinking this means there are no problems?
You certainly would be.
The compiler is only available when there is changed code to compile. If any (compiler level) problems are detected they will be reported and the compile will fail.
NB. Some problems cannot be detected by the compiler so it's not proof of perfect code - it's a very good check to do first though.
Feb 13 '07 #19

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

Similar topics

3
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...
14
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...
25
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...
9
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...
10
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...
0
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...
2
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...
13
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...
10
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....
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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
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
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...

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.