473,563 Members | 2,695 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deleting in vba code

My problem is how could I get previos record in the form after I had
deleted the current record.
What should I write after code below ? docmd.showallre cords or what ?
If I do so I'll get error message: "Index or primary key cannot
contain a Null Value"

I'am trying to delete current record with following code in vba:

Private Sub Delete_record (glngLasno as long)

Set dbsCurrent = CurrentDb()
strSql = "SELECT * FROM bill where [company]= '" & gstrComp & "'
and lasno = " & glngLasno & ";"
Set rstBill = dbsCurrent.Open Recordset(strSq l)

If rstBill.EOF Or rstBill.BOF Then

Set dbsCurrent = Nothing
Set rstBill = Nothing
Exit Sub
End If
Application.Ech o False
Do Until rstBill.EOF

rstBill.Delete
rstBill.MoveNex t
Loop
MsgBox ("Deleted !")
rstBill.Close
dbsCurrent.Clos e
Set dbsCurrent = Nothing
Set rstBill = Nothing
Application.Ech o True
Exit Sub
err_sec:
Set dbsCurrent = Nothing
Set rstBill = Nothing

MsgBox Err.Description
Exit Sub
End Sub

Colpo
Nov 12 '05 #1
3 4351
Try
strSQL = DELETE * FROM bill where [company]= '" & gstrComp & "' and [lasno]
= " & glngLasno & ";"
dbsCurrent.Exec ute strSQL, dbFailOnError

This should be much faster than stepping through a recordset one record at a
time.
--
Wayne Morgan
Microsoft Access MVP
"Timppa" <co***@jippii.f i> wrote in message
news:37******** *************** ***@posting.goo gle.com...
My problem is how could I get previos record in the form after I had
deleted the current record.
What should I write after code below ? docmd.showallre cords or what ?
If I do so I'll get error message: "Index or primary key cannot
contain a Null Value"

I'am trying to delete current record with following code in vba:

Private Sub Delete_record (glngLasno as long)

Set dbsCurrent = CurrentDb()
strSql = "SELECT * FROM bill where [company]= '" & gstrComp & "'
and lasno = " & glngLasno & ";"
Set rstBill = dbsCurrent.Open Recordset(strSq l)

If rstBill.EOF Or rstBill.BOF Then

Set dbsCurrent = Nothing
Set rstBill = Nothing
Exit Sub
End If
Application.Ech o False
Do Until rstBill.EOF

rstBill.Delete
rstBill.MoveNex t
Loop
MsgBox ("Deleted !")
rstBill.Close
dbsCurrent.Clos e
Set dbsCurrent = Nothing
Set rstBill = Nothing
Application.Ech o True
Exit Sub
err_sec:
Set dbsCurrent = Nothing
Set rstBill = Nothing

MsgBox Err.Description
Exit Sub
End Sub

Colpo

Nov 12 '05 #2
co***@jippii.fi (Timppa) wrote in message news:<37******* *************** ****@posting.go ogle.com>...
My problem is how could I get previos record in the form after I had
deleted the current record.
What should I write after code below ? docmd.showallre cords or what ?
If I do so I'll get error message: "Index or primary key cannot
contain a Null Value"

I'am trying to delete current record with following code in vba:

Private Sub Delete_record (glngLasno as long)

Set dbsCurrent = CurrentDb()
strSql = "SELECT * FROM bill where [company]= '" & gstrComp & "'
and lasno = " & glngLasno & ";"
Set rstBill = dbsCurrent.Open Recordset(strSq l)

If rstBill.EOF Or rstBill.BOF Then

Set dbsCurrent = Nothing
Set rstBill = Nothing
Exit Sub
End If
Application.Ech o False
Do Until rstBill.EOF

rstBill.Delete
rstBill.MoveNex t
Loop
MsgBox ("Deleted !")
rstBill.Close
dbsCurrent.Clos e
Set dbsCurrent = Nothing
Set rstBill = Nothing
Application.Ech o True
Exit Sub
err_sec:
Set dbsCurrent = Nothing
Set rstBill = Nothing

MsgBox Err.Description
Exit Sub
End Sub

Colpo

Don't know if this will help, but I use the following code found on
the Dev Ashish web site.

Private Sub DeleteCurrentRe cord_Click()
If Not (fDelCurrentRec (Me)) Then
MsgBox "An Error occurred!"
End If
End Sub
The actual function is:

'************** Code Start *************
Function fDelCurrentRec( ByRef frmSomeForm As Form) As Boolean
On Error GoTo Err_Section

With frmSomeForm
If .NewRecord Then
.Undo
fDelCurrentRec = True
GoTo Exit_Section
End If
End With

With frmSomeForm.Rec ordsetClone
.Bookmark = frmSomeForm.Boo kmark
.Delete
frmSomeForm.Req uery
End With
fDelCurrentRec = True
Exit_Section:
Exit Function

Err_Section:
fDelCurrentRec = False
Resume Exit_Section
End Function
'************** Code End *************
Nov 12 '05 #3
dn*****@accurid e.com (David Neagle) wrote in message news:<bf******* *************** ****@posting.go ogle.com>...
co***@jippii.fi (Timppa) wrote in message news:<37******* *************** ****@posting.go ogle.com>...
My problem is how could I get previos record in the form after I had
deleted the current record.
What should I write after code below ? docmd.showallre cords or what ?
If I do so I'll get error message: "Index or primary key cannot
contain a Null Value"

I'am trying to delete current record with following code in vba:

Private Sub Delete_record (glngLasno as long)

Set dbsCurrent = CurrentDb()
strSql = "SELECT * FROM bill where [company]= '" & gstrComp & "'
and lasno = " & glngLasno & ";"
Set rstBill = dbsCurrent.Open Recordset(strSq l)

If rstBill.EOF Or rstBill.BOF Then

Set dbsCurrent = Nothing
Set rstBill = Nothing
Exit Sub
End If
Application.Ech o False
Do Until rstBill.EOF

rstBill.Delete
rstBill.MoveNex t
Loop
MsgBox ("Deleted !")
rstBill.Close
dbsCurrent.Clos e
Set dbsCurrent = Nothing
Set rstBill = Nothing
Application.Ech o True
Exit Sub
err_sec:
Set dbsCurrent = Nothing
Set rstBill = Nothing

MsgBox Err.Description
Exit Sub
End Sub

Colpo

Don't know if this will help, but I use the following code found on
the Dev Ashish web site.

Private Sub DeleteCurrentRe cord_Click()
If Not (fDelCurrentRec (Me)) Then
MsgBox "An Error occurred!"
End If
End Sub
The actual function is:

'************** Code Start *************
Function fDelCurrentRec( ByRef frmSomeForm As Form) As Boolean
On Error GoTo Err_Section

With frmSomeForm
If .NewRecord Then
.Undo
fDelCurrentRec = True
GoTo Exit_Section
End If
End With

With frmSomeForm.Rec ordsetClone
.Bookmark = frmSomeForm.Boo kmark
.Delete
frmSomeForm.Req uery
End With
fDelCurrentRec = True
Exit_Section:
Exit Function

Err_Section:
fDelCurrentRec = False
Resume Exit_Section
End Function
'************** Code End *************

Thanks for your advice David, but there is still problems with
"frmSomeForm.Re query " There comes error with it. Otherwise it works
fine.

There is such functionality that I choose a bill from Form 1 (in list
box) and
after that the control moves to the Form 2. In the Form 2 I'll try to
delete the current record. In the Form 2 I'll like to see previos
record after deletion. That's what doesn't work now.
I hope you undestand what I mean.

Colpo
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
3578
by: Rick | last post by:
Hi, Does deleting an object more than one times incur undefined behavior? I think it doesn't but just making sure... thanks Rick
6
1644
by: Abhijeet | last post by:
I was just toying around idea of deleting this from a member function. Was expecting that any acess to member variable or function after deleting sould give me dump(segmetation violation).Cause now I am trying to access freed. memory. Is my assumption correct? I tried following code ---------------------------------------------------...
5
14722
by: Mojtaba Faridzad | last post by:
Hi, with SetDataBinding( ) a DataGrid shows a DataView. user can select some rows in the grid by holding cotrol key. when user clicks on Delete button, I should delete all selected rows. I am trying to delete these lines from the dataview like this: for (int i=0; i < dataView.Count; i++) if (dataGrid.IsSelected(i)) dataView.Delete(i);
4
14002
by: al havrilla | last post by:
hi all what does the phrase: "scalar deleting destructor" mean? i'm getting this in a debug error message using c++ 7.1 thanks Al
6
4548
by: Martin Bischoff | last post by:
Hi, I'm creating temporary directories in my web app (e.g. ~/data/temp/temp123) to allow users to upload files. When I later delete these directories (from the code behind), the application restarts and all active sessions are terminated. This error is also described in detail here:...
46
4386
by: DP | last post by:
hi, i've got a form, with a subform in it. i've got a delete button in the subform. the code i;ve got is; Private Sub cmdDeleteRecord_Click() msg = "Are you sure you want to delete this film rental record?" Style = vbYesNo + vbQuestion + vbDefaultButton2
3
2866
by: Kimera.Kimera | last post by:
I'm trying to write a program in VB.net 2003 that basically deletes all files, folders, sub-folders and sub-sub folders (etc). The program is simply for deleting the Windows/Temp folder contents, removing all the files/folders inside it. The problem i am having is that i can only delete files in the Windows/Temp folder, and i can't delete...
2
1912
Parul Bagadia
by: Parul Bagadia | last post by:
I have written a code for deleting certain value from linklist; it's not working; where as i have written one for deleting a no., after given no. which works fine! I even debugged it; but invain; down here am posting my code; please somebody who can point it out; let me know fast; whats wrong in it... //Delete a number next to the given...
2
2105
by: padmaneha | last post by:
Hi I have created two tables 'TrainsMaster' & 'TransArrvlDepinfo' Columns which I have created in 'TrainsMaster' are 'trainName,TrainNo, StartStaionId, & EndstationId' Columns which I have created in ''TransArrvlDepinfo' are 'Stationcode, TrainNo, Arrvaltime,Depttime' I have to delete few trains from 'TrainsMaster' for which the...
4
2383
by: sphinney | last post by:
I'm not exactly sure how to start this post. My question is pretty simple, but it will take a little bit of context before I can state it. (And thanks in advance for taking the time to read this!) Context: What I'm essentially trying to do is create a poor man's document imaging system in Access 2007. I have a database that contains forms and...
0
7664
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...
0
7583
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7638
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...
0
7948
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...
0
6250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
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...
0
5213
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...
1
2082
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.