473,785 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Saving Problem

72 New Member
Hi there vb masters i have a problem regrading the saving procedure in my program:

Here my code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSave_Click()
  2. Dim rsShowRec As New ADODB.Recordset
  3. Dim cnn As New ADODB.Connection
  4.  
  5. Set cnn = New ADODB.Connection
  6. cnn.ConnectionString = _
  7.  "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  8.           "Data Source=" & App.Path & "\dbTimeScheduling2.mdb;"
  9. cnn.Open
  10.  
  11. For x = 0 To 15
  12. On Error Resume Next
  13. rsShowRec.Source = "Select * from RECORDS where [SUBJECT CODES] = ' " & txtCode(x).Text & " '"
  14. rsShowRec.Open , cnn, adOpenStatic, adLockOptimistic
  15.  
  16.     If Combo1(x).Text = "Select" Or Combo2(x).Text = "Select" Or Combo3(x).Text = "Select" Or Combo4(x).Text = "Select" Then
  17.         MsgBox ("Cannot Save blank entries"), vbCritical
  18.         rsShowRec.Close
  19.         cnn.Close
  20.         Exit Sub
  21.     Else
  22.  
  23.         If rsShowRec.BOF = True Then
  24.  
  25.                 rsShowRec.AddNew
  26.  
  27.                 If IsNull(txtCode(x).Text) Then rsShowRec.Fields("SUBJECT CODES") = "" Else rsShowRec.Fields("SUBJECT CODES") = txtCode(x).Text
  28.                 If IsNull(Combo1(x).Text) Then rsShowRec.Fields("TimeStart") = "" Else rsShowRec.Fields("TimeStart") = Combo1(x).Text
  29.                 If IsNull(Combo2(x).Text) Then rsShowRec.Fields("TimeEnd") = "" Else rsShowRec.Fields("TimeEnd") = Combo4(x).Text
  30.                 If IsNull(Combo4(x).Text) Then rsShowRec.Fields("ROOM") = "" Else rsShowRec.Fields("ROOM") = Combo2(x).Text
  31.                 If IsNull(Combo3(x).Text) Then rsShowRec.Fields("DAYS") = "" Else rsShowRec.Fields("DAYS") = Combo3(x).Text
  32.                 If IsNull(txtBlock.Text) Then rsShowRec.Fields("BLOCK SECTION") = "" Else rsShowRec.Fields("BLOCK SECTION") = txtBlock.Text
  33.                 If IsNull(txtSY.Text) Then rsShowRec.Fields("SCHOOL YEAR") = "" Else rsShowRec.Fields("SCHOOL YEAR") = txtSY.Text
  34.  
  35.                 rsShowRec.Update
  36.                 rsShowRec.Requery
  37.             Set rsShowRec = Nothing
  38.         End If
  39.  
  40.  
  41.  
  42.     End If
  43.     Next
  44.         MsgBox ("Data Saved!"), vbOKOnly
  45.  
  46.  
  47. End Sub
  48.  
My problem is like this everytime i try to save some records in the table called "RECORDS", it saves it stores all the data in the table.. but the first row of the my table "RECORDS", that consist of field namely "TimeStart" , "TimeEnd", "ROOM", "DAYS". Everytime it save it always put an empty row in the first row of my fields,,

I dont know how i can prevent it, i dont want to have empty rows in my fields in any location. Please help me...

I hope someone can crack whats wrong with my code or how can i code it...

Thank you very much.
Jun 8 '07 #1
2 1573
jeffbroodwar
118 New Member
Hi,

I saw your code..... i think there's a problem with the "If BOF == true then rs.addnew... you see if it reaches the (Beginning Of File) the addnew method of your recordset doesn't add the new record in that position.... meaning, the addnew method always adds a new record into the next row.

ex :

if your at row 3 of your database

1
2
3 rs position..... if you try to invoke the addnew method here it'll save data at position 4 of your database. leaving 3rd position blank.... though i didn't try to paste your code in vb6 ide and tried it. I hope my suggestion will solve your problem...

Best Regards,
Jeff
Jun 8 '07 #2
nairda
39 New Member
Hi there vb masters i have a problem regrading the saving procedure in my program:

Here my code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSave_Click()
  2. Dim rsShowRec As New ADODB.Recordset
  3. Dim cnn As New ADODB.Connection
  4.  
  5. Set cnn = New ADODB.Connection
  6. cnn.ConnectionString = _
  7.  "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  8.           "Data Source=" & App.Path & "\dbTimeScheduling2.mdb;"
  9. cnn.Open
  10.  
  11. For x = 0 To 15
  12. On Error Resume Next
  13. rsShowRec.Source = "Select * from RECORDS where [SUBJECT CODES] = ' " & txtCode(x).Text & " '"
  14. rsShowRec.Open , cnn, adOpenStatic, adLockOptimistic
  15.  
  16.     If Combo1(x).Text = "Select" Or Combo2(x).Text = "Select" Or Combo3(x).Text = "Select" Or Combo4(x).Text = "Select" Then
  17.         MsgBox ("Cannot Save blank entries"), vbCritical
  18.         rsShowRec.Close
  19.         cnn.Close
  20.         Exit Sub
  21.     Else
  22.  
  23.         If rsShowRec.BOF = True Then
  24.  
  25.                 rsShowRec.AddNew
  26.  
  27.                 If IsNull(txtCode(x).Text) Then rsShowRec.Fields("SUBJECT CODES") = "" Else rsShowRec.Fields("SUBJECT CODES") = txtCode(x).Text
  28.                 If IsNull(Combo1(x).Text) Then rsShowRec.Fields("TimeStart") = "" Else rsShowRec.Fields("TimeStart") = Combo1(x).Text
  29.                 If IsNull(Combo2(x).Text) Then rsShowRec.Fields("TimeEnd") = "" Else rsShowRec.Fields("TimeEnd") = Combo4(x).Text
  30.                 If IsNull(Combo4(x).Text) Then rsShowRec.Fields("ROOM") = "" Else rsShowRec.Fields("ROOM") = Combo2(x).Text
  31.                 If IsNull(Combo3(x).Text) Then rsShowRec.Fields("DAYS") = "" Else rsShowRec.Fields("DAYS") = Combo3(x).Text
  32.                 If IsNull(txtBlock.Text) Then rsShowRec.Fields("BLOCK SECTION") = "" Else rsShowRec.Fields("BLOCK SECTION") = txtBlock.Text
  33.                 If IsNull(txtSY.Text) Then rsShowRec.Fields("SCHOOL YEAR") = "" Else rsShowRec.Fields("SCHOOL YEAR") = txtSY.Text
  34.  
  35.                 rsShowRec.Update
  36.                 rsShowRec.Requery
  37.             Set rsShowRec = Nothing
  38.         End If
  39.  
  40.  
  41.  
  42.     End If
  43.     Next
  44.         MsgBox ("Data Saved!"), vbOKOnly
  45.  
  46.  
  47. End Sub
  48.  
My problem is like this everytime i try to save some records in the table called "RECORDS", it saves it stores all the data in the table.. but the first row of the my table "RECORDS", that consist of field namely "TimeStart" , "TimeEnd", "ROOM", "DAYS". Everytime it save it always put an empty row in the first row of my fields,,

I dont know how i can prevent it, i dont want to have empty rows in my fields in any location. Please help me...

I hope someone can crack whats wrong with my code or how can i code it...

Thank you very much.
Hi Darrel,
I think you don't need the BOF

If you want to put a new data in your database table, you don't have to look for your table's BOF or EOF.
Example:
Expand|Select|Wrap|Line Numbers
  1. With rs
  2.                         .AddNew
  3.                         !TIMESTART = Text1.Text
  4.                         !TIMEEND = Text2.Text
  5.                         !ROOM = Text3.Text
  6.                         !DAYS = Text4.Text
  7.                         .Update
  8.                     End With
It would be different if you want to UPDATE your data, you have to search for your data until EOF is reached

I hope this would help

NAIRDA
Jun 8 '07 #3

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

Similar topics

1
1789
by: Lovely Angel For You | last post by:
Dear Friends Hope you all doing great. I have this problem. When I try to save any ASP page, I get the message that "The page will not save correctly". Even though I go ahead and when I go offline the space of images is blank. I have this website also where I am using ASP pages and my users are
7
7528
by: G-Factor | last post by:
Hi all I've just started learning about saving files. I got bit of a problem. The following code gives me an error about incompatible types. (Cannot covert from class character to char *). I would appreciate it if anyone could either help me out, or direct me to an online resource site that has information on saving/loading classes. I have found several tutorials, but they either do not really help (saving text files) or are too...
4
48240
by: Michael Kennedy [UB] | last post by:
Hi Everyone, I have this multithreaded C# windows forms application which does a lot of image processing. Occasionally, I get the following error: A generic error occurred in GDI+. System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
2
1827
by: manning_news | last post by:
Has anyone had a problem with Access 2003 not saving their coding? I've been using 2003 for a couple of months now and just this week noticed that some coding I'd done for a database was not there anymore. I reentered it and didn't have any problems for a couple of days. Today I entered some coding, saved it, opened another database, and when I opened my original database again, the coding I had entered was missing. Access 2000 always...
2
3765
by: Peder Y | last post by:
My code is something like this: --------------- Image img = Image.FromFile("somefile.bmp"); FileStream fStream = new FileStream("someBinaryFile.dat"); BinaryWriter bw = new BinaryWriter(fStream); img.Save(bw.BaseStream, ImageFormat.Bmp);
4
6724
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my code ?? thank you Pedro Leite From Portugal ------------------------------------
6
6455
by: Mark Denardo | last post by:
My question is similar to one someone posted a few months back, but I don't see any replies. Basically I want to be able to have users upload photos and save them in a database (as byte data) and be able to load them to an image webcontrol, but system.web.ui.webcontrols.image only seems to have a control to load the image from a URL. There's no way to load this directly without saving the image as a file and then using...
2
2144
by: =?Utf-8?B?bWFydGluMQ==?= | last post by:
Hi, All, My app picks ccurrent time on the PC to retrieve data from sql DB, the Sql data is always data with non-daylight saving. The app runs on PC with both daylight saving and non-daylight saving. So the question is how to check the PC is daylight saving or not? can anyone know this piece code to handle this problem? Thanks in advance, Martin
9
2397
by: Wingot | last post by:
Hey, I am using Visual Studio 2008 Beta 2 for some application development in C#, but I presume that the following question applies equally well to any environment.
1
1711
by: Charming12 | last post by:
Hi All, I am facing quite a unique problem here with DayLight saving time. I know Windows handles Daylight saving time internally to sync PC Clock . But now i need to pass the Information of Daylight Saving period i.e, From When To When it is applied . For e.g. In US it is From 2nd Sunday in March to 1st Sunday in November. I need to get this period for all timeZones in my .Net application using Windows API.
0
9483
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
10157
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10096
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
7504
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
6742
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();...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
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
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
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.