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

Moving records from one database to another database

18
I have a Delete button with this code atached

Expand|Select|Wrap|Line Numbers
  1. Private Sub Delete_Click()
  2.  
  3. On Error GoTo Err_DoArchive
  4.   Dim ws As DAO.Workspace
  5.   Dim db As DAO.Database
  6.   Dim bInTrans As Boolean
  7.   Dim strSql As String
  8.   Dim strMsg As String
  9.   Dim r As String
  10.  
  11. If IsNull(Combo15) Or Combo15 = "" Then
  12. MsgBox "You must select a PATIENT", vbOKOnly, "Select A PATIENT"
  13. Exit Sub
  14. End If
  15.  
  16. r = MsgBox("!!!WARNING!!! Are you sure you want to DELETE this PATIENTS FILE this CAN NOT be UNDONE!!", vbYesNo, "!!!!WARNING!!!!      Deletion of PATIENTS File       !!!!WARNING!!!!")
  17. If r = 6 Then GoTo YES Else GoTo NO
  18.  
  19. NO:
  20.     Me.NotSick = False
  21.     DoCmd.Save
  22.     DoCmd.Close
  23. Exit Sub
  24.  
  25. YES:
  26.     DoCmd.Save
  27.  
  28.   Set ws = DBEngine(0)
  29.   ws.BeginTrans
  30.   bInTrans = True
  31.   Set db = ws(0)
  32.  
  33.  
  34.   strSql = "INSERT INTO Deleted ( Id, FirstName, Surname, Dob, Doctor, Diagnosis, Notes ) " & _
  35.     "IN ""x:\SickList\Archived.mdb"" " & _
  36.     "SELECT Id, FirstName, Surname, Dob, Doctor, Diagnosis, Notes FROM qfound WHERE (NotSick = true);"
  37.   db.Execute strSql, dbFailOnError
  38.  
  39.   strSql = "DELETE FROM qfound WHERE (NotSick = true);"
  40.   db.Execute strSql, dbFailOnError
  41.  
  42. strMsg = "Archive " & db.RecordsAffected & " record(s)?"
  43.   If MsgBox(strMsg, vbOKCancel + vbQuestion, "Confirm") = vbOK Then
  44.     ws.CommitTrans
  45.     bInTrans = False
  46.   End If
  47.  
  48. Exit_DoArchive:
  49.  
  50.   On Error Resume Next
  51.   Set db = Nothing
  52.   If bInTrans Then
  53.     ws.Rollback
  54.   End If
  55.   Set ws = Nothing
  56.   DoCmd.Close
  57.   MsgBox "Patient Deleted"
  58.   Exit Sub
  59.  
  60. Err_DoArchive:
  61.   MsgBox Err.Description, vbExclamation, "Archiving failed: Error " & Err.Number
  62.   Resume Exit_DoArchive
  63.   End Sub
The field NotSick is set to true when someone selects a name from a combobox
by using the following code
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo15_AfterUpdate()
  2.     Me.RecordsetClone.FindFirst "[ID] = " & Me![Combo15]
  3.     Me.Bookmark = Me.RecordsetClone.Bookmark
  4.     foundme = Me.Bookmark
  5.     Me.NotSick = True
  6.     DoCmd.Save
  7. End Sub
it works but the problem is you have to close form and then go back in and try again at lest once

can anyone give me some advice on how to fix this problem

thank you in advance for any help ;-)
Mar 6 '07 #1
8 2636
NeoPa
32,556 Expert Mod 16PB
Can you explain what it is you're trying to do with this code (Just the AfterUpdate procedure).
I can't see any sensible logic to it, but then perhaps that's because I don't know what you're trying to achieve.
Mar 8 '07 #2
powelly
18
Sorry

I`m doing this as i don`t want to lose any information when some one is deleted and i don`t want them in the same data base.

The code searches a feild (NotSick) that is true which is set from the user selecting a person then the patient is exported to my other database then that same patient is deleted.

Hope this clears my idea up a bit

thank you
Mar 18 '07 #3
NeoPa
32,556 Expert Mod 16PB
Maybe someone can understand what you want better than I can, but I don't think you've actually said anywhere what isn't happening as you would like.
I could ask some general questions as to why you seem to want to save the design of your form in your code (DoCmd.Save), but I don't think that's what you're trying to ask about.
You're not even asking how to do what you want to do. you seem to have you ideas about that, but something isn't to your liking. My problem is that you don't tell me what this is (other than referrring to it obliquely).
I get the concept of what you're trying to do but not of what isn't working for you.
Mar 19 '07 #4
powelly
18
DoCmd.Save was a mistake in the code it has been removed but problem still exist

The problem (bottom of page) is i have two databases one called sicklist and one archived when a patient is selected on the deleted Form the following code runs
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo15_AfterUpdate()
  2.     Me.RecordsetClone.FindFirst "[ID] = " & Me![Combo15]
  3.     Me.Bookmark = Me.RecordsetClone.Bookmark
  4.     foundme = Me.Bookmark
  5.     Me.NotSick = True
  6. End Sub
this just sets patient to be archived and then deleted
due to the field(NotSick = true)
the code for the archiving and deletion is
Expand|Select|Wrap|Line Numbers
  1. Private Sub Delete_Click()
  2.  
  3. On Error GoTo Err_DoArchive
  4.   Dim ws As DAO.Workspace
  5.   Dim db As DAO.Database
  6.   Dim bInTrans As Boolean
  7.   Dim strSql As String
  8.   Dim strMsg As String
  9.   Dim r As String
  10.  
  11. If IsNull(Combo15) Or Combo15 = "" Then
  12. MsgBox "You must select a PATIENT", vbOKOnly, "Select A PATIENT"
  13. Exit Sub
  14. End If
  15.  
  16. r = MsgBox("!!!WARNING!!! Are you sure you want to DELETE this PATIENTS FILE this CAN NOT be UNDONE!!", vbYesNo, "!!!!WARNING!!!!      Deletion of PATIENTS File       !!!!WARNING!!!!")
  17. If r = 6 Then GoTo YES Else GoTo NO
  18.  
  19. NO:
  20.     Me.NotSick = False
  21.     DoCmd.Save
  22.     DoCmd.Close
  23. Exit Sub
  24.  
  25. YES:
  26.     DoCmd.Save
  27.  
  28.   Set ws = DBEngine(0)
  29.   ws.BeginTrans
  30.   bInTrans = True
  31.   Set db = ws(0)
  32.  
  33.  
  34.   strSql = "INSERT INTO Deleted ( Id, FirstName, Surname, Dob, Doctor, Diagnosis, Notes ) " & _
  35.     "IN ""x:\SickList\Archived.mdb"" " & _
  36.     "SELECT Id, FirstName, Surname, Dob, Doctor, Diagnosis, Notes FROM qfound WHERE (NotSick = true);"
  37.   db.Execute strSql, dbFailOnError
  38.  
  39.   strSql = "DELETE FROM qfound WHERE (NotSick = true);"
  40.   db.Execute strSql, dbFailOnError
  41.  
  42. strMsg = "Archive " & db.RecordsAffected & " record(s)?"
  43.   If MsgBox(strMsg, vbOKCancel + vbQuestion, "Confirm") = vbOK Then
  44.     ws.CommitTrans
  45.     bInTrans = False
  46.   End If
  47.  
  48. Exit_DoArchive:
  49.  
  50.   On Error Resume Next
  51.   Set db = Nothing
  52.   If bInTrans Then
  53.     ws.Rollback
  54.   End If
  55.   Set ws = Nothing
  56.   DoCmd.Close
  57.   MsgBox "Patient Deleted"
  58.   Exit Sub
  59.  
  60. Err_DoArchive:
  61.   MsgBox Err.Description, vbExclamation, "Archiving failed: Error " & Err.Number
  62.   Resume Exit_DoArchive
  63.   End Sub
PROBLEM is I have to close form and re open the form and re run the code to make the archiving and deletion to finish i would like it to run in 1 open instead of closing & reopening the form to make it finish the archiving and deletion is this possible and i hope this makes it easer to understand
Mar 26 '07 #5
NeoPa
32,556 Expert Mod 16PB
is this possible and i hope this makes it easer to understand
No, not really.
No punctuation; and random words left out. It didn't make much sense to me and I'm not going to waste my time trying to understand, when you can't be bothered to follow the guidelines and make it clear.
Would this make any sense to you? I doubt it.
You've been told once that it makes little sense. It seems you've not made any effort to make it clearer. I will try to help if and when I understand what you're saying without having to read it through over and over again.
Mar 26 '07 #6
Lfuboi
1
It sounds like your Form is just not updating the information after the data has changed. Because of that, you have to close the form and reopen it to show the data change.

Maybe a simple solution to this would be using the Command Button Wizard, choose "Form Operations" and choose "Refresh Form Data."

This will prevent you from having to close out your Form and reopen it.

It looks like you're WAY ahead of me in Access knowledge. I'm still wet behind the ears. I don't know anything about the code you have...I don't even know what an expression is, yet. But it sounds like you're just annoyed that you have to close and restart your form...and I think this is a simple solution.
Apr 6 '07 #7
powelly
18
Thanks Lfuboi for your reply yes thats the problem i`m having

Your suggestion
Maybe a simple solution to this would be using the Command Button Wizard, choose "Form Operations" and choose "Refresh Form Data."
is on the right track but unlucky the code will not Re Run :-(

thanks again you gave me something to look into, to fix the problem

i`ll post any new info or the fix to this problem

Cheers :-)
Apr 11 '07 #8
powelly
18
I have found a NEAR fix but still some times it won`t work straight away which does not matter because when the user opens another form it will finish the code when they go back to main menu

I split the code into different parts, to try and make it work more efficiently

On Activate
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Activate()
  2. DoCmd.Maximize
  3. On Error GoTo Err_DoArchive
  4.   Dim ws As DAO.Workspace
  5.   Dim db As DAO.Database
  6.   Dim bInTrans As Boolean
  7.   Dim strSql As String
  8.   Dim strMsg As String
  9.  
  10.  
  11.   Set ws = DBEngine(0)
  12.   ws.BeginTrans
  13.   bInTrans = True
  14.   Set db = ws(0)
  15.  
  16.   strSql = "INSERT INTO Deleted ( Id, FirstName, Surname, Dob, Doctor, Diagnosis, Notes ) " & _
  17.     "IN ""x:\SickList\Archived.mdb"" " & _
  18.     "SELECT Id, FirstName, Surname, Dob, Doctor, Diagnosis, Notes FROM [all] WHERE (NotSick = true);"
  19.   db.Execute strSql, dbFailOnError
  20.  
  21.   strSql = "DELETE FROM [all] WHERE (NotSick = true);"
  22.   db.Execute strSql, dbFailOnError
  23.  
  24.     ws.CommitTrans
  25.     bInTrans = False
  26.  
  27. Exit_DoArchive:
  28.  
  29.   On Error Resume Next
  30.   Set db = Nothing
  31.   If bInTrans Then
  32.     ws.Rollback
  33.   End If
  34.   Set ws = Nothing
  35.   Exit Sub
  36.  
  37. Err_DoArchive:
  38.   MsgBox Err.Description, vbExclamation, "Archiving failed: Error " & Err.Number
  39.   Resume Exit_DoArchive
  40.  
  41. Exit Sub
  42.  
  43. End Sub
and
On Open

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.  
  3.     Dim dbsSickList As Database
  4.     Dim rstAll As DAO.Recordset
  5.     Dim strEntrydate As String
  6.     Dim oldate
  7.  
  8. Set dbsSickList = OpenDatabase("x:\SickList\SickList.mdb")
  9. Set rstAll = _
  10.      dbsSickList.OpenRecordset("All", _
  11.      dbOpenDynaset)
  12.  
  13.  
  14.     oldate = Date
  15.     oldate = DateAdd("d", -31, oldate)
  16.  
  17.  
  18.     With rstAll
  19.     .MoveFirst
  20.  
  21. Search:
  22.    Do While Not .EOF
  23.       If !Entrydate < oldate Then GoTo Old Else GoTo Newd
  24.  
  25.  
  26. Newd:
  27. .MoveNext
  28.     GoTo Search
  29.  
  30. Old:
  31. .Edit
  32. !NotSick = True
  33. .Update
  34. .MoveNext
  35. GoTo Search
  36. Loop
  37. End With
  38.  
  39.     rstAll.Close
  40.     Set rstAll = Nothing
  41.     Set dbsSickList = Nothing
  42.  
  43.   End Sub
this is not a complete fix but it may help some one to fix a problem they have i will continue posting this until it is working like i would like it to

cheers to all
May 9 '07 #9

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

Similar topics

6
by: Hemant Shah | last post by:
Folks, I need to move HOME directory of an instance to another directory. What is the best way of doing it? Is changing password file enough? or dies DB2 store this info in it's own config? ...
2
by: Wayne Aprato | last post by:
I've read most, if not all, of the posts on moving average and still can't find a simple solution to my problem (if a simple solution exists!) I have a table with 2 fields: Hours and Injuries. I...
1
by: Alienz | last post by:
I'm sure this is easy so if you have a sec pls help me out thx. Let say I have an inventory table and at the end of the month I want to move the info in 1 field (total end of month 1) into...
15
by: Deano | last post by:
I've posted about this subject before but haven't really got anywhere yet. I have now come up with a plan of action that takes into account my strong desire to implement save/discard functionality...
3
by: genojoe | last post by:
I have tried everything I can think of to move records from one Access database to another. It should not be that hard. Read on.... I have identical access mdb's. One contains data; one...
3
by: Iavor Raytchev | last post by:
Hello, We a situation with a central database that contains the data that needs to be presented at N off-line terminals (N can be 5 000 can be 15 000). Each terminal presents unique data. The...
7
by: =?Utf-8?B?TW9iaWxlTWFu?= | last post by:
Hello everyone: I am looking for everyone's thoughts on moving large amounts (actually, not very large, but large enough that I'm throwing exceptions using the default configurations). We're...
1
by: Parasyke | last post by:
Thanks in advance... I need to on a subform in datasheet view to be able to, instead of delete a record, move that record to another table. I can if needed turn the subform into a continuous form...
1
by: =?Utf-8?B?UmljaA==?= | last post by:
In a database search application (vb2005), the user wants to be able to scroll through records using the mousewheel. The data display form contains textboxes for the main data and a datagridview...
3
by: c0l0nelFlagg | last post by:
I have a moving dispatcher database. There are 99 drivers, 99 loaders, and 50 different vehicles. The scheduler database is built on a 13 4 week month year so that it can be used repeatedly in any...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.