I have a Delete button with this code atached - Private Sub Delete_Click()
-
-
On Error GoTo Err_DoArchive
-
Dim ws As DAO.Workspace
-
Dim db As DAO.Database
-
Dim bInTrans As Boolean
-
Dim strSql As String
-
Dim strMsg As String
-
Dim r As String
-
-
If IsNull(Combo15) Or Combo15 = "" Then
-
MsgBox "You must select a PATIENT", vbOKOnly, "Select A PATIENT"
-
Exit Sub
-
End If
-
-
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!!!!")
-
If r = 6 Then GoTo YES Else GoTo NO
-
-
NO:
-
Me.NotSick = False
-
DoCmd.Save
-
DoCmd.Close
-
Exit Sub
-
-
YES:
-
DoCmd.Save
-
-
Set ws = DBEngine(0)
-
ws.BeginTrans
-
bInTrans = True
-
Set db = ws(0)
-
-
-
strSql = "INSERT INTO Deleted ( Id, FirstName, Surname, Dob, Doctor, Diagnosis, Notes ) " & _
-
"IN ""x:\SickList\Archived.mdb"" " & _
-
"SELECT Id, FirstName, Surname, Dob, Doctor, Diagnosis, Notes FROM qfound WHERE (NotSick = true);"
-
db.Execute strSql, dbFailOnError
-
-
strSql = "DELETE FROM qfound WHERE (NotSick = true);"
-
db.Execute strSql, dbFailOnError
-
-
strMsg = "Archive " & db.RecordsAffected & " record(s)?"
-
If MsgBox(strMsg, vbOKCancel + vbQuestion, "Confirm") = vbOK Then
-
ws.CommitTrans
-
bInTrans = False
-
End If
-
-
Exit_DoArchive:
-
-
On Error Resume Next
-
Set db = Nothing
-
If bInTrans Then
-
ws.Rollback
-
End If
-
Set ws = Nothing
-
DoCmd.Close
-
MsgBox "Patient Deleted"
-
Exit Sub
-
-
Err_DoArchive:
-
MsgBox Err.Description, vbExclamation, "Archiving failed: Error " & Err.Number
-
Resume Exit_DoArchive
-
End Sub
The field NotSick is set to true when someone selects a name from a combobox
by using the following code - Private Sub Combo15_AfterUpdate()
-
Me.RecordsetClone.FindFirst "[ID] = " & Me![Combo15]
-
Me.Bookmark = Me.RecordsetClone.Bookmark
-
foundme = Me.Bookmark
-
Me.NotSick = True
-
DoCmd.Save
-
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 ;-)
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.
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
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.
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 - Private Sub Combo15_AfterUpdate()
-
Me.RecordsetClone.FindFirst "[ID] = " & Me![Combo15]
-
Me.Bookmark = Me.RecordsetClone.Bookmark
-
foundme = Me.Bookmark
-
Me.NotSick = True
-
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 - Private Sub Delete_Click()
-
-
On Error GoTo Err_DoArchive
-
Dim ws As DAO.Workspace
-
Dim db As DAO.Database
-
Dim bInTrans As Boolean
-
Dim strSql As String
-
Dim strMsg As String
-
Dim r As String
-
-
If IsNull(Combo15) Or Combo15 = "" Then
-
MsgBox "You must select a PATIENT", vbOKOnly, "Select A PATIENT"
-
Exit Sub
-
End If
-
-
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!!!!")
-
If r = 6 Then GoTo YES Else GoTo NO
-
-
NO:
-
Me.NotSick = False
-
DoCmd.Save
-
DoCmd.Close
-
Exit Sub
-
-
YES:
-
DoCmd.Save
-
-
Set ws = DBEngine(0)
-
ws.BeginTrans
-
bInTrans = True
-
Set db = ws(0)
-
-
-
strSql = "INSERT INTO Deleted ( Id, FirstName, Surname, Dob, Doctor, Diagnosis, Notes ) " & _
-
"IN ""x:\SickList\Archived.mdb"" " & _
-
"SELECT Id, FirstName, Surname, Dob, Doctor, Diagnosis, Notes FROM qfound WHERE (NotSick = true);"
-
db.Execute strSql, dbFailOnError
-
-
strSql = "DELETE FROM qfound WHERE (NotSick = true);"
-
db.Execute strSql, dbFailOnError
-
-
strMsg = "Archive " & db.RecordsAffected & " record(s)?"
-
If MsgBox(strMsg, vbOKCancel + vbQuestion, "Confirm") = vbOK Then
-
ws.CommitTrans
-
bInTrans = False
-
End If
-
-
Exit_DoArchive:
-
-
On Error Resume Next
-
Set db = Nothing
-
If bInTrans Then
-
ws.Rollback
-
End If
-
Set ws = Nothing
-
DoCmd.Close
-
MsgBox "Patient Deleted"
-
Exit Sub
-
-
Err_DoArchive:
-
MsgBox Err.Description, vbExclamation, "Archiving failed: Error " & Err.Number
-
Resume Exit_DoArchive
-
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
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.
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.
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 :-)
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 - Private Sub Form_Activate()
-
DoCmd.Maximize
-
On Error GoTo Err_DoArchive
-
Dim ws As DAO.Workspace
-
Dim db As DAO.Database
-
Dim bInTrans As Boolean
-
Dim strSql As String
-
Dim strMsg As String
-
-
-
Set ws = DBEngine(0)
-
ws.BeginTrans
-
bInTrans = True
-
Set db = ws(0)
-
-
strSql = "INSERT INTO Deleted ( Id, FirstName, Surname, Dob, Doctor, Diagnosis, Notes ) " & _
-
"IN ""x:\SickList\Archived.mdb"" " & _
-
"SELECT Id, FirstName, Surname, Dob, Doctor, Diagnosis, Notes FROM [all] WHERE (NotSick = true);"
-
db.Execute strSql, dbFailOnError
-
-
strSql = "DELETE FROM [all] WHERE (NotSick = true);"
-
db.Execute strSql, dbFailOnError
-
-
ws.CommitTrans
-
bInTrans = False
-
-
Exit_DoArchive:
-
-
On Error Resume Next
-
Set db = Nothing
-
If bInTrans Then
-
ws.Rollback
-
End If
-
Set ws = Nothing
-
Exit Sub
-
-
Err_DoArchive:
-
MsgBox Err.Description, vbExclamation, "Archiving failed: Error " & Err.Number
-
Resume Exit_DoArchive
-
-
Exit Sub
-
-
End Sub
and
On Open - Private Sub Form_Open(Cancel As Integer)
-
-
Dim dbsSickList As Database
-
Dim rstAll As DAO.Recordset
-
Dim strEntrydate As String
-
Dim oldate
-
-
Set dbsSickList = OpenDatabase("x:\SickList\SickList.mdb")
-
Set rstAll = _
-
dbsSickList.OpenRecordset("All", _
-
dbOpenDynaset)
-
-
-
oldate = Date
-
oldate = DateAdd("d", -31, oldate)
-
-
-
With rstAll
-
.MoveFirst
-
-
Search:
-
Do While Not .EOF
-
If !Entrydate < oldate Then GoTo Old Else GoTo Newd
-
-
-
Newd:
-
.MoveNext
-
GoTo Search
-
-
Old:
-
.Edit
-
!NotSick = True
-
.Update
-
.MoveNext
-
GoTo Search
-
Loop
-
End With
-
-
rstAll.Close
-
Set rstAll = Nothing
-
Set dbsSickList = Nothing
-
-
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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?
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
| |