473,288 Members | 1,704 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

Saving Problem

72
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 1550
jeffbroodwar
118 100+
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
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
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...
7
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...
4
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+....
2
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...
2
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...
4
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...
6
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)...
2
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...
9
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
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...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.