473,499 Members | 1,669 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.showallrecords 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.OpenRecordset(strSql)

If rstBill.EOF Or rstBill.BOF Then

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

rstBill.Delete
rstBill.MoveNext
Loop
MsgBox ("Deleted !")
rstBill.Close
dbsCurrent.Close
Set dbsCurrent = Nothing
Set rstBill = Nothing
Application.Echo True
Exit Sub
err_sec:
Set dbsCurrent = Nothing
Set rstBill = Nothing

MsgBox Err.Description
Exit Sub
End Sub

Colpo
Nov 12 '05 #1
3 4349
Try
strSQL = DELETE * FROM bill where [company]= '" & gstrComp & "' and [lasno]
= " & glngLasno & ";"
dbsCurrent.Execute 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.fi> wrote in message
news:37**************************@posting.google.c om...
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.showallrecords 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.OpenRecordset(strSql)

If rstBill.EOF Or rstBill.BOF Then

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

rstBill.Delete
rstBill.MoveNext
Loop
MsgBox ("Deleted !")
rstBill.Close
dbsCurrent.Close
Set dbsCurrent = Nothing
Set rstBill = Nothing
Application.Echo 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.google. 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.showallrecords 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.OpenRecordset(strSql)

If rstBill.EOF Or rstBill.BOF Then

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

rstBill.Delete
rstBill.MoveNext
Loop
MsgBox ("Deleted !")
rstBill.Close
dbsCurrent.Close
Set dbsCurrent = Nothing
Set rstBill = Nothing
Application.Echo 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 DeleteCurrentRecord_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.RecordsetClone
.Bookmark = frmSomeForm.Bookmark
.Delete
frmSomeForm.Requery
End With
fDelCurrentRec = True
Exit_Section:
Exit Function

Err_Section:
fDelCurrentRec = False
Resume Exit_Section
End Function
'************** Code End *************
Nov 12 '05 #3
dn*****@accuride.com (David Neagle) wrote in message news:<bf**************************@posting.google. com>...
co***@jippii.fi (Timppa) wrote in message news:<37**************************@posting.google. 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.showallrecords 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.OpenRecordset(strSql)

If rstBill.EOF Or rstBill.BOF Then

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

rstBill.Delete
rstBill.MoveNext
Loop
MsgBox ("Deleted !")
rstBill.Close
dbsCurrent.Close
Set dbsCurrent = Nothing
Set rstBill = Nothing
Application.Echo 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 DeleteCurrentRecord_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.RecordsetClone
.Bookmark = frmSomeForm.Bookmark
.Delete
frmSomeForm.Requery
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.Requery " 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
3573
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
1641
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...
5
14714
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...
4
13997
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
4540
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...
46
4364
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...
3
2861
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,...
2
1903
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;...
2
2101
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...
4
2376
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!) ...
0
7014
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
7229
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...
1
6905
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
7395
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...
0
5485
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,...
1
4921
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...
0
4609
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...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.