473,809 Members | 2,876 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deleting Row from Data File

63 New Member
Hey, I'm using the following code to write entries to a data file and then read them in an msflexgrid. I now would like to add code under a delete button to use the table(grid) to delete rows from the file. How can I do that. I have some code for deleting a row from the table, but it's only deleting the row from the table, and not the entry itself. Please help! Is there a relatively easy way to do this ?

Private Sub cmdAddDelivery_ Click()

Open App.Path & "\deliveries.tx t" For Append As #11
Write #11, lblAccNum.Capti on, txtPName.Text, txtPAddress1.Te xt & ", " & txtPAddress2.Te xt & ", " & cboPTown.Text, cboPPrefix.Text & " " & txtPTelephone.T ext & ", " & cboPMPrefix.Tex t & " " & txtPMobile.Text , txtDName.Text, txtDAddress1.Te xt & ", " & txtDAddress2.Te xt & ", " & cboDTown.Text, cboDPrefix.Text & " " & txtDTelephone.T ext & ", " & cboDMPrefix.Tex t & " " & txtDMobile.Text , txtWeightOfPack age.Text, txtDeliveryPric e.Text, txtPickupDate.T ext, txtDeliveryDate .Text, lblPriorityLeve l.Caption

MsgBox "New Delivery has been Added !", vbInformation, "Success!!! "

txtPName.Text = ""
txtPAddress1.Te xt = ""
txtPAddress2.Te xt = ""
cboPTown.Text = ""
cboPPrefix.Text = "021"
txtPTelephone.T ext = ""
cboPMPrefix.Tex t = "085"
txtPMobile.Text = ""

txtDName.Text = ""
txtDAddress1.Te xt = ""
txtDAddress2.Te xt = ""
cboDTown.Text = ""
cboDPrefix.Text = "021"
txtDTelephone.T ext = ""
cboDMPrefix.Tex t = "085"
txtDMobile.Text = ""
txtWeightOfPack age.Text = ""
txtDeliveryPric e.Text = ""
txtPickupDate.T ext = ""
txtDeliveryDate .Text = ""

txtPName.SetFoc us

Close #11

End Sub

Private Sub tabAdmin_Click( PreviousTab As Integer)

If tabAdmin.Tab = 1 Then

Open App.Path & "\deliveries.tx t" For Input As #12

Dim oldRow As Long
Dim lngRow As Long
Dim lngCol As Long

Dim tRow As Long
Dim tCol As Long

Dim strID As String
Dim strPickupName As String
Dim strPickupAdd As String
Dim strPickupTel As String
Dim strDelName As String
Dim strDelAdd As String
Dim strDelTel As String
Dim strWoP As String
Dim strDelPrice As String
Dim strPickupDate As String
Dim strDelDate As String
Dim strPriority As String
Dim counter As Integer


MSFlexGrid1.Row s = 2

Do Until EOF(12)
Input #12, strID, strPickupName, strPickupAdd, strPickupTel, strDelName, strDelAdd, strDelTel, strWoP, strDelPrice, strPickupDate, strDelDate, strPriority

MSFlexGrid1.Tex tMatrix(1, 0) = strID
MSFlexGrid1.Tex tMatrix(1, 1) = strPickupName
MSFlexGrid1.Tex tMatrix(1, 2) = strPickupAdd
MSFlexGrid1.Tex tMatrix(1, 3) = strPickupTel
MSFlexGrid1.Tex tMatrix(1, 4) = strDelName
MSFlexGrid1.Tex tMatrix(1, 5) = strDelAdd
MSFlexGrid1.Tex tMatrix(1, 6) = strDelTel
MSFlexGrid1.Tex tMatrix(1, 7) = strWoP
MSFlexGrid1.Tex tMatrix(1, 8) = strDelPrice
MSFlexGrid1.Tex tMatrix(1, 9) = strPickupDate
MSFlexGrid1.Tex tMatrix(1, 10) = strDelDate
MSFlexGrid1.Tex tMatrix(1, 11) = strPriority

MSFlexGrid1.Row s = MSFlexGrid1.Row s + 1
For lngRow = MSFlexGrid1.Row s - 2 To MSFlexGrid1.Row Step -1
For lngCol = 0 To MSFlexGrid1.Col s - 1
MSFlexGrid1.Tex tMatrix(lngRow + 1, lngCol) = MSFlexGrid1.Tex tMatrix(lngRow, lngCol)
If lngRow = MSFlexGrid1.Row Then
MSFlexGrid1.Tex tMatrix(lngRow, lngCol) = "" 'Make the current row empty
End If
Next
Next

Loop

End If

Close #12

End Sub
Feb 27 '08 #1
4 1480
VBWheaties
145 New Member
My approach would be to write a routine that reads values off the grid into a temp file. Once its done reading values off the grid, save the Temp file as the primary file.
Feb 27 '08 #2
MiziaQ
63 New Member
How can I do that ? Could you please give a coded example ? Thanks
Feb 27 '08 #3
VBWheaties
145 New Member
How can I do that ? Could you please give a coded example ? Thanks
It's real easy to do this.
I see you already know how to reference TextMatrix and you know how to open/close files. So basically

1. Create a sub (call it WriteGridToFile or something)
2. Open any arbitrary file giving a temp file name. Open for writing (or output)
2. In a loop, enumerate the rows of the grid.
3. For each row, read the TextMatrix values into variables, or simply write to the file directly using TextMatrix. Your choice.
4. Once done looping the grid rows, writing the values to file, close the file.
5. Save the Temp file as your primary source file, overwriting the primary file.
6. Call WriteGridToFile whenever you need to persist (save) changes.

Let me know if you need help on anything else.
Feb 27 '08 #4
MiziaQ
63 New Member
Hey :) Thanks a lot for your help. I have one last thing to do, and that is to replace the files, which I don't know how to do. Once again, thanks !
Feb 27 '08 #5

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

Similar topics

1
2809
by: John Baker | last post by:
Hi: I am working with an XLS file, andhave Access 2000. When I try and clear the xlf file (so that xls can use it for additional data), I get an error message: "Deleting data in a linked table is not supported by this ISAM. (Error 3617)"
13
9545
by: Bob Darlington | last post by:
I have a repair and backup database routine which runs when a user closes down my application. It works fine in my development machine, but breaks on a client's at the following line: If Dir(strLDB) <> "" Then Kill (strLDB) where strLDB is the path to the ldb file. The client advises that the ldb doesn't lurk after the program closes. Any ideas?
3
2999
by: kris.dorey | last post by:
Hi, Ive got the following code which seems ok but when the user runs the function for a second time I get an error message stating that the mdb is in use by another process. There is still an ldb for the life of the application even after calling oldebconnection.close and gc.collect. Any ideas?
2
2137
by: melanieab | last post by:
Hi, I'm deleting nodes in my xml file, and it does seem to work, but then when I later reload the file and make an xmlNodeList, the nodelist count still includes the deleted nodes yet the file shows no sign of them. Here is what I have: Example of my xml: <Catalog> <File ID = "1"> <Customer>Me</Customer>
2
1552
by: GMK | last post by:
Dear all in my asp.net application i have a text file that is installed with my application on the server. this text file is filled with data through a web interface in my application. i need to know how could i update this text file programatically and using a web interface. what i need is not to over write the content of the text file but to delete it's content and then write a new content. id there any way to do this?
8
14034
by: shandra | last post by:
I have a file I need to delete or truncate. I tried using the KILL command in VB6. I tried using the file.delete command in VB.net. I tried manually deleting, renaming, and copying over the file... but nothing works. I keep getting the error: Cannot delete access_log: it is being used by another person or program. I tried shutting down services, I tried killing processes using the task manager, I tried rebooting, and still, I get...
2
1716
by: SiouxieQ | last post by:
Hi there, I'm using the code below to try to delete a name from a list of names in a file. Unfortunately it doesn't quite do what I want it to. Instead of looking for the name in the textbox and deleting that it is just deleting the first line of data in the file.
0
1791
by: John Yale | last post by:
I am using an XmlDocument to save some data. Periodically I add new data and save the XmlDocument to a file: Me.fXmlDoc.Save(Me.fFilename) When I have added all the data I need, I want to move the file to a new location which I do by saving the file to the new location, and then deleting the old one: Me.fXmlDoc.Save(newFilePath)
2
1552
by: emphyrio | last post by:
Hi, I am new to programming in vb. net. I have this problem: I created a form with a datagrid. I can add records and then save them to a XML file, using this code on the click event of a button (my dataset is called Maxdata1): Dim fs As Stream Me.BindingContext(Maxdata1, "addresses").EndCurrentEdit() fs = New FileStream("D:\temp\maxdata.xml", FileMode.OpenOrCreate) Maxdata1.WriteXml(fs) ...
0
9721
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10633
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10114
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9198
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7651
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4331
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
3
3011
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.