HI,
I have created a form with various text boxes around.... i want as soon as sombody will click on the save button the data will be saved in a database called mydb.mdb......i m a very newbie to this vb....kindly help.....i have written code as below.....but geting an error of "c:\incidentreport\incidentreportmydb.mdb not found"
Whereas i am keeping the database in the same path as the error is coming.
Private Sub cmdAdd_Click()
Dim conec As New ADODB.Connection
Dim rs As New ADODB.Recordset
conec.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source ='" & App.Path & "MyDB.mdb'"
conec.CursorLocation = adUseClient
conec.Open
rs.Open "select * from clients where Client_Id='" & txtUserName.Text & "'", conec, adOpenKeyset, adLockOptimistic
If txtUserName.Text = "" Then
MsgBox "Please fill the Client Id Number", vbCritical
Else
With rs
' Search for identical/matching STUDENTCODE
If rs.RecordCount = 0 Then '---> If there's no identical/matching Clientid, then save as new data
.AddNew
End If
!clientid = txtUserName.Text
!clientname = txtName_First.Text
!clientADDRESS = txtName_Last.Text
.Update
End With
End If
End Sub
kindly help me in geting this minor problem resolved.
when i debug error gets highlighted in cn.open
5 1576
Private Sub cmdAdd_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & strMyDB & ";"
cn.CursorLocation = adUseClient
cn.Open
strSQL = "SELECT * FROM clients" & " WHERE client_id=" & FixApostrophies(txtClient_Id.Text)
rs.Open strSQL, cn, adOpenForwardOnly, adLockOptimistic
If txtName_First.Text = "" Then
MsgBox "Please fill the Student Code Number", vbCritical
Else
With rs
' Search for identical/matching Clientid
If rs.RecordCount = 0 Then '---> If there's no identical/matching STUDENTCODE, then save as new data
.AddNew
End If
!clientCODE = txtUsername.Text
!clientNAME = txtName_First.Text
!clientADDRESS = txtName_Last.Text
.Update
End With
End If
End Sub
i have resolved the earilier problem now i got stuck with some other problem..
and i am geting syntex error missing some query expression in 'client_Id='
I am not geting any idea of how to deal with it....please somebody help me.
below is the code what i did
Private Sub cmdAdd_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & strMyDB & ";"
cn.CursorLocation = adUseClient
cn.Open
strSQL = "SELECT * FROM clients" & " WHERE client_id=" & FixApostrophies(txtClient_Id.Text)
rs.Open strSQL, cn, adOpenForwardOnly, adLockOptimistic
If txtName_First.Text = "" Then
MsgBox "Please fill the Student Code Number", vbCritical
Else
With rs
' Search for identical/matching Clientid
If rs.RecordCount = 0 Then '---> If there's no identical/matching STUDENTCODE, then save as new data
.AddNew
End If
!clientCODE = txtUsername.Text
!clientNAME = txtName_First.Text
!clientADDRESS = txtName_Last.Text
.Update
End With
End If
End Sub
- conec.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source ='" & App.Path & "MyDB.mdb'"
You have to check here App.Path & "MyDB.mdb'"
that should be App.Path & "\MyDB.mdb'"
like - conec.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source ='" & App.Path & "\MyDB.mdb'"
Thanx hariharan
i got rid of this problem..
Now the problem is somthing different.
Now i am geting syntex error missing some query expression in 'client_Id='
I am not geting any idea of how to deal with it....please somebody help me.
See here the code.
Private Sub cmdAdd_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & strMyDB & ";"
cn.CursorLocation = adUseClient
cn.Open
strSQL = "SELECT * FROM clients" & "WHERE client_id="" "
rs.Open strSQL, cn, adOpenDynamic, adLockOptimistic
If txtName_First.Text = "" Then
MsgBox "Please fill the Student Code Number", vbCritical
Else
With rs
' Search for identical/matching Clientid
If rs.RecordCount = 0 Then '---> If there's no identical/matching STUDENTCODE, then save as new data
.AddNew
End If
!clientCODE = txtUsername.Text
!clientNAME = txtName_First.Text
!clientADDRESS = txtName_Last.Text
.Update
End With
End If
End Sub
- strSQL = "SELECT * FROM clients" & "WHERE client_id="" "
that also simple.
just check this line, you gave 3 double quotes there is no value to select in where clause. -
strSQL = "SELECT * FROM clients WHERE client_id=" & valNumericToSelect & ""
this will better
Thanx hariharan
i got rid of this problem..
Now the problem is somthing different.
Now i am geting syntex error missing some query expression in 'client_Id='
I am not geting any idea of how to deal with it....please somebody help me.
See here the code.
Private Sub cmdAdd_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & strMyDB & ";"
cn.CursorLocation = adUseClient
cn.Open
strSQL = "SELECT * FROM clients" & "WHERE client_id="" "
rs.Open strSQL, cn, adOpenDynamic, adLockOptimistic
If txtName_First.Text = "" Then
MsgBox "Please fill the Student Code Number", vbCritical
Else
With rs
' Search for identical/matching Clientid
If rs.RecordCount = 0 Then '---> If there's no identical/matching STUDENTCODE, then save as new data
.AddNew
End If
!clientCODE = txtUsername.Text
!clientNAME = txtName_First.Text
!clientADDRESS = txtName_Last.Text
.Update
End With
End If
End Sub
Hi,
Not very Sure, What is the field name of ID? coz, in SQL Statement u search for "client_id" and in ur RS AddNew, u refer to as "ClientCode".
may be the table does not have client_id as field name...?
REgards
Veena
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Andras Gilicz |
last post by:
Hi VB fans
I'm working on a relatively large project in VB6 with about a dozen
forms, including graphs, labels, text boxes, etc. The software itself
is actually a flow simulator with more or...
|
by: WJA |
last post by:
I'm probably missing something here but I can't understand the
following. When 2 users try to save a record with the same primary key
(a number field), the first record saves as expected, but the...
|
by: Rameel |
last post by:
Friends,
I'm probably being more critical with VB.Net Windows application.
I have Developed VisualStudio 20005 VB.Net Windows application
how willl i be able to save a specific record into my...
|
by: rockdc1981 |
last post by:
I dont it is possible to put this codes together.. I want to prompt the user to save the record and at the same time have a log of audit trail. the codes work out fine separately.
Code for Audit...
|
by: Ian |
last post by:
I am trying to save the current record on a form before opening a
report, doesn’t sound to hard does it? The code on a buttons on click
event goes like this:
DoCmd.DoMenuItem acFormBar,...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |