First Post - Access Db Help - EDIT

Hi All.

This is my first post here I I'll would like to say help to everyone.

I'm haveing some problem's with editing within my VB6 app?

This is my code below;

Private Sub ButCustSearch_Click()

Dim v_sSQL As String
Dim v_rsFind As New Recordset
Dim v_iLoop As Integer
Dim v_sActiveConnection As String
Dim v_iIndex As Integer
Dim AppPath As String
Dim CorrectRecord As Integer

' Checking the Field are not all blank.

If txt_MemberID.Text = "" And tbx_SName.Text = "" Then

MsgBox "Please Select a Criteria", vbInformation + vbOKOnly, "Record Search"
Exit Sub

End If

AppPath = frm_currentuser.TxtAppPath.Text
CorrectRecord = 7
On Error GoTo Err


v_sActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & AppPath
v_sSQL = "SELECT * FROM Tbl_Customer_Details WHERE "


If tbx_SName.Text = "" Then

v_sSQL = v_sSQL & "Customer_ID LIKE '" & txt_MemberID.Text & "'"

Else

v_sSQL = v_sSQL & "Surname LIKE '" & tbx_SName.Text & "'"

End If

' v_sSQL = Left(v_sSQL, Len(v_sSQL) - 5)
v_rsFind.Open v_sSQL, v_sActiveConnection

While Not v_rsFind.EOF And CorrectRecord = 7

v_iIndex = v_iIndex + 1

' Displaying Results

txt_MemberID.Text = v_rsFind.Fields!Customer_ID
txt_Db_Title.Text = v_rsFind.Fields!Title
tbx_FName.Text = v_rsFind.Fields!Forenames
tbx_SName.Text = v_rsFind.Fields!Surname
dtpDOB.value = v_rsFind.Fields!DOB
txtTimeDate.Text = v_rsFind.Fields!Reg_Date
txt_Db_Gender.Text = v_rsFind.Fields!Gender

CorrectRecord = MsgBox("Is this the Correct Record", vbQuestion + vbYesNo, "Record")

v_rsFind.MoveNext

Wend

If CorrectRecord = 7 Then

MsgBox "End Of Record Search, No more current records have the requested Criteria", vbInformation + vbOKOnly, "Record Search"


End If

If CorrectRecord = 6 Then

' will not be able to change the Member ID

txt_MemberID.Enabled = False


End If

' v_rsFind.Close

Exit Sub

Err:
MsgBox Err.Description, vbCritical

End Sub

Now if I changed the text in i.e. tbx_SName.Text how would I store that back in my Db (I'm using Access 97)
[2794 byte] By [huttojb] at [2007-11-20 0:41:07]
# 1 Re: First Post - Access Db Help - EDIT
Hello friend and welcome to dev-archive!

Are you trying to edit the information the database?
I'm not realy clear on your problem.

And also when posting use '[CODE]' tags.
Sabin_33 at 2007-11-9 19:56:51 >
# 2 Re: First Post - Access Db Help - EDIT
yeah - I'm trying to edit the information within the database.

I'll explain my program - firstly I seach for a field and the display the remaining of the entry, I then want to edit a field (or multiply field's) within the database.

If you can help I will be greatful.

Jason
huttojb at 2007-11-9 19:57:50 >
# 3 Re: First Post - Access Db Help - EDIT
Can anyone help me on this, or do i just put it down to a lost cause!!!!!

Jason
huttojb at 2007-11-9 19:58:54 >
# 4 Re: First Post - Access Db Help - EDIT
You should have a primary key (a field that uniquely identifies a record) before you can update a specific record in an Access database. I assume it is the Customer_ID, by looking at your code you can code like this..

set cn = new ADODB.Connection
cn.open "<your connection string here>"

txt_MemberID.Text = v_rsFind.Fields!Customer_ID
txt_Db_Title.Text = v_rsFind.Fields!Title
tbx_FName.Text = v_rsFind.Fields!Forenames
tbx_SName.Text = v_rsFind.Fields!Surname
dtpDOB.value = v_rsFind.Fields!DOB
txtTimeDate.Text = v_rsFind.Fields!Reg_Date
txt_Db_Gender.Text = v_rsFind.Fields!Gender

cn.Execute "UPDATE <Table> SET Title = '" & Replace$(txt_Db_Title.text, "'", "''") & "', " & _
"Forenames = '" & Replace$(tbx_FName.text, "'", "''") & "', " & _
"Surname= '" & Replace$(tbx_SName.text, "'", "''") & "', " & _
"DOB = #" & dtpDOB.value & "#, " & _
"Reg_Date = #" & txtTimeDate.text & "#, " & _
"Gender= '" & Replace$(txt_Db_Gender.text, "'", "''") & "' " & _
"WHERE Customer_ID = " & txt_MemberID.text,, adcmdtext or adexecutenorecords

cn.close
set cn = nothing

The field-value expressions in the SQL will depend on the table structure and field defitions of the database. You can enhance the code so that only those fields that are actually changed where get updated in the SQL.. etc
:wave:
Thread1 at 2007-11-9 19:59:49 >
# 5 Re: First Post - Access Db Help - EDIT
Thank you Thread1,

I will try this tonight and let you know how i get on, thanks again, cos i'm having real problems with this.

jason
huttojb at 2007-11-9 20:00:57 >
# 6 Re: First Post - Access Db Help - EDIT
Works a dream - thank you.....
huttojb at 2007-11-9 20:01:51 >