Hi there vb masters i have a problem regrading the saving procedure in my program:
Here my code: -
Private Sub cmdSave_Click()
-
Dim rsShowRec As New ADODB.Recordset
-
Dim cnn As New ADODB.Connection
-
-
Set cnn = New ADODB.Connection
-
cnn.ConnectionString = _
-
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
-
"Data Source=" & App.Path & "\dbTimeScheduling2.mdb;"
-
cnn.Open
-
-
For x = 0 To 15
-
On Error Resume Next
-
rsShowRec.Source = "Select * from RECORDS where [SUBJECT CODES] = ' " & txtCode(x).Text & " '"
-
rsShowRec.Open , cnn, adOpenStatic, adLockOptimistic
-
-
If Combo1(x).Text = "Select" Or Combo2(x).Text = "Select" Or Combo3(x).Text = "Select" Or Combo4(x).Text = "Select" Then
-
MsgBox ("Cannot Save blank entries"), vbCritical
-
rsShowRec.Close
-
cnn.Close
-
Exit Sub
-
Else
-
-
If rsShowRec.BOF = True Then
-
-
rsShowRec.AddNew
-
-
If IsNull(txtCode(x).Text) Then rsShowRec.Fields("SUBJECT CODES") = "" Else rsShowRec.Fields("SUBJECT CODES") = txtCode(x).Text
-
If IsNull(Combo1(x).Text) Then rsShowRec.Fields("TimeStart") = "" Else rsShowRec.Fields("TimeStart") = Combo1(x).Text
-
If IsNull(Combo2(x).Text) Then rsShowRec.Fields("TimeEnd") = "" Else rsShowRec.Fields("TimeEnd") = Combo4(x).Text
-
If IsNull(Combo4(x).Text) Then rsShowRec.Fields("ROOM") = "" Else rsShowRec.Fields("ROOM") = Combo2(x).Text
-
If IsNull(Combo3(x).Text) Then rsShowRec.Fields("DAYS") = "" Else rsShowRec.Fields("DAYS") = Combo3(x).Text
-
If IsNull(txtBlock.Text) Then rsShowRec.Fields("BLOCK SECTION") = "" Else rsShowRec.Fields("BLOCK SECTION") = txtBlock.Text
-
If IsNull(txtSY.Text) Then rsShowRec.Fields("SCHOOL YEAR") = "" Else rsShowRec.Fields("SCHOOL YEAR") = txtSY.Text
-
-
rsShowRec.Update
-
rsShowRec.Requery
-
Set rsShowRec = Nothing
-
End If
-
-
-
-
End If
-
Next
-
MsgBox ("Data Saved!"), vbOKOnly
-
-
-
End Sub
-
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.
2 1550
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
Hi there vb masters i have a problem regrading the saving procedure in my program:
Here my code: -
Private Sub cmdSave_Click()
-
Dim rsShowRec As New ADODB.Recordset
-
Dim cnn As New ADODB.Connection
-
-
Set cnn = New ADODB.Connection
-
cnn.ConnectionString = _
-
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
-
"Data Source=" & App.Path & "\dbTimeScheduling2.mdb;"
-
cnn.Open
-
-
For x = 0 To 15
-
On Error Resume Next
-
rsShowRec.Source = "Select * from RECORDS where [SUBJECT CODES] = ' " & txtCode(x).Text & " '"
-
rsShowRec.Open , cnn, adOpenStatic, adLockOptimistic
-
-
If Combo1(x).Text = "Select" Or Combo2(x).Text = "Select" Or Combo3(x).Text = "Select" Or Combo4(x).Text = "Select" Then
-
MsgBox ("Cannot Save blank entries"), vbCritical
-
rsShowRec.Close
-
cnn.Close
-
Exit Sub
-
Else
-
-
If rsShowRec.BOF = True Then
-
-
rsShowRec.AddNew
-
-
If IsNull(txtCode(x).Text) Then rsShowRec.Fields("SUBJECT CODES") = "" Else rsShowRec.Fields("SUBJECT CODES") = txtCode(x).Text
-
If IsNull(Combo1(x).Text) Then rsShowRec.Fields("TimeStart") = "" Else rsShowRec.Fields("TimeStart") = Combo1(x).Text
-
If IsNull(Combo2(x).Text) Then rsShowRec.Fields("TimeEnd") = "" Else rsShowRec.Fields("TimeEnd") = Combo4(x).Text
-
If IsNull(Combo4(x).Text) Then rsShowRec.Fields("ROOM") = "" Else rsShowRec.Fields("ROOM") = Combo2(x).Text
-
If IsNull(Combo3(x).Text) Then rsShowRec.Fields("DAYS") = "" Else rsShowRec.Fields("DAYS") = Combo3(x).Text
-
If IsNull(txtBlock.Text) Then rsShowRec.Fields("BLOCK SECTION") = "" Else rsShowRec.Fields("BLOCK SECTION") = txtBlock.Text
-
If IsNull(txtSY.Text) Then rsShowRec.Fields("SCHOOL YEAR") = "" Else rsShowRec.Fields("SCHOOL YEAR") = txtSY.Text
-
-
rsShowRec.Update
-
rsShowRec.Requery
-
Set rsShowRec = Nothing
-
End If
-
-
-
-
End If
-
Next
-
MsgBox ("Data Saved!"), vbOKOnly
-
-
-
End Sub
-
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: - With rs
-
.AddNew
-
!TIMESTART = Text1.Text
-
!TIMEEND = Text2.Text
-
!ROOM = Text3.Text
-
!DAYS = Text4.Text
-
.Update
-
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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+....
|
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...
|
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...
|
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...
|
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)...
|
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...
|
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.
|
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...
|
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"....
|
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...
|
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...
|
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 =...
|
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...
|
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...
|
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...
|
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...
|
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)...
| |