|
-
April 4th, 2012, 04:24 AM
#1
Sir can you please help me on my codes about Save Button I wonder what's wrong on my code here is my code:
Code:
Dim ctrl As Control
Dim Adodc1 As Adodc
Validate_inputs
If ValidateEntries Then
'Confirm Saving Records...
Adodc1.Recordset.Update
Else
Adodc1.Recordset.Fields("Hospital No.") = Text1.Text
Adodc1.Recordset.Fields("Patient No.") = Text2.Text
Adodc1.Recordset.Fields("Patient Name") = Text3.Text
Adodc1.Recordset.Fields("Age") = Text4.Text
Adodc1.Recordset.Fields("BirthDate") = Text5.Text
Adodc1.Recordset.Fields("Address") = Text6.Text
Adodc1.Recordset.Fields("Telephone No") = Text7.Text
Adodc1.Recordset.Fields("Civil Status") = Text8.Text
Adodc1.Recordset.Fields("Date Admitted") = Text9.Text
Adodc1.Recordset.Fields("Room Type") = Text10.Text
Adodc1.Recordset.Fields("Room No.") = Text11.Text
Adodc1.Recordset.Fields("Guardian") = Text12.Text
Adodc1.Recordset.Fields("GAddress") = Text13.Text
Adodc1.Recordset.Fields("Attending Physician") = Text14.Text
Adodc1.Recordset.Update
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Text6.Enabled = False
Text7.Enabled = False
Text8.Enabled = False
Text9.Enabled = False
Text10.Enabled = False
Text11.Enabled = False
Text12.Enabled = False
Text13.Enabled = False
Text14.Enabled = False
CmdSave.Enabled = True
End If
End Sub
Sir What is the Code for Edit,Cancel And Search? How to code a fast pace of searching?
Last edited by Cimperiali; April 5th, 2012 at 07:08 AM.
Reason: Same posts from same author
-
April 4th, 2012, 07:35 PM
#2
Re: VB6 Save Button Command
You are updating the record BEFORE getting info from the fields (Unless you do it twice). Also, might have to format for the correct data-type of your fields
-
April 5th, 2012, 06:01 AM
#3
Re: VB6 Save Button Command
There is no special code to edit.
If you have unbound textfields, you fill the textfields with the contents of the record's fields and let the user edit each field.
The Save button mus then do this (in Pseudocode)
Code:
btnSave_Click()
If ValidateAllInput then
Recordset.Field("FieldName) = Textx.Text
...repeat for all fields
Recordset.Update
EndIf
End Sub
As long as you don't call RecordsetUpdate no change to the record should occur.
If you make a new record, you first clear all textfields, then you do
Recordset.AddNew (to add a new record to the table)
Then again you let the user entwer data.
The Save Button works exactly like before.
The Cancel button should simple refill the textboxes with the fields from the recordset.
But in case you have added a new record, you have to do
Recordset.CancelUpdate
to remove the record you had added with .AddNew
and then display the record you had displayed before.
There are some features of the Recordset object which help reminding which was the last record.Read up on the .BookMark property.
Also I'd suggest you look for small samples of complete working code.
-
April 5th, 2012, 08:34 AM
#4
Re: VB6 Save Button Command
Sir what is the with this when i run it and input an example Information then when i click save button it didn't work here is the code:
Dim ctrl As Control
Dim Adodc1 As Adodc
If ValidateEntries Then
'Confirm Saving Records...
If MsgBox("Click Ok to Save", vbInformation + vbOKCancel) = vbOK Then
Adodc1.Recordset.AddNew 'New Record
Else
End If
Adodc1.Recordset.Fields("Hospital No.") = Text1.Text
Adodc1.Recordset.Fields("Patient No.") = Text2.Text
Adodc1.Recordset.Fields("Patient Name") = Text3.Text
Adodc1.Recordset.Fields("Age") = Text4.Text
Adodc1.Recordset.Fields("BirthDate") = Text5.Text
Adodc1.Recordset.Fields("Address") = Text6.Text
Adodc1.Recordset.Fields("Telephone No") = Text7.Text
Adodc1.Recordset.Fields("Civil Status") = Text8.Text
Adodc1.Recordset.Fields("Date Admitted") = Text9.Text
Adodc1.Recordset.Fields("Room Type") = Text10.Text
Adodc1.Recordset.Fields("Room No.") = Text11.Text
Adodc1.Recordset.Fields("Guardian") = Text12.Text
Adodc1.Recordset.Fields("GAddress") = Text13.Text
Adodc1.Recordset.Fields("Attending Physician") = Text14.Text
Adodc1.Recordset.Update
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Text6.Enabled = False
Text7.Enabled = False
Text8.Enabled = False
Text9.Enabled = False
Text10.Enabled = False
Text11.Enabled = False
Text12.Enabled = False
Text13.Enabled = False
Text14.Enabled = False
CmdSave.Enabled = True
Else
End If
End Sub
-
April 6th, 2012, 08:10 AM
#5
Re: VB6 Save Button Command
 Originally Posted by Sulapas
it didn't work here is the code:
what didn't work??
data is not add in database.
it shows error message.
.
.
.
so on.
pleae you can explain a bit more
so we would can help you.
-
April 6th, 2012, 08:34 AM
#6
Re: VB6 Save Button Command
sorry for the post the code that didn't work is this:
[code]
Dim ctrl As Control
Dim Adodc1 As Adodc
If ValidateEntries Then
'Confirm Saving Records...
If MsgBox("Click Ok to Save", vbInformation + vbOKCancel) = vbOK Then
Adodc1.Recordset.AddNew 'New Record
Else
End If
Adodc1.Recordset.Fields("Hospital No.") = Text1.Text
Adodc1.Recordset.Fields("Patient No.") = Text2.Text
Adodc1.Recordset.Fields("Patient Name") = Text3.Text
Adodc1.Recordset.Fields("Age") = Text4.Text
Adodc1.Recordset.Fields("BirthDate") = Text5.Text
Adodc1.Recordset.Fields("Address") = Text6.Text
Adodc1.Recordset.Fields("Telephone No") = Text7.Text
Adodc1.Recordset.Fields("Civil Status") = Text8.Text
Adodc1.Recordset.Fields("Date Admitted") = Text9.Text
Adodc1.Recordset.Fields("Room Type") = Text10.Text
Adodc1.Recordset.Fields("Room No.") = Text11.Text
Adodc1.Recordset.Fields("Guardian") = Text12.Text
Adodc1.Recordset.Fields("GAddress") = Text13.Text
Adodc1.Recordset.Fields("Attending Physician") = Text14.Text
Adodc1.Recordset.Update
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Text6.Enabled = False
Text7.Enabled = False
Text8.Enabled = False
Text9.Enabled = False
Text10.Enabled = False
Text11.Enabled = False
Text12.Enabled = False
Text13.Enabled = False
Text14.Enabled = False
CmdSave.Enabled = True
Else
End If
End Sub
[code]
-
April 6th, 2012, 05:43 PM
#7
Re: VB6 Save Button Command
Edit the post, and add / to the CLOSING TAG of code.
Also, what does the SAVE button code look like?
-
April 9th, 2012, 02:40 PM
#8
Re: VB6 Save Button Command
Try the following .
Code:
If ValidateEntries Then
Adodc1.Recordset.Fields("Hospital No.") = Text1.Text
Adodc1.Recordset.Fields("Patient No.") = Text2.Text
Adodc1.Recordset.Fields("Patient Name") = Text3.Text
Adodc1.Recordset.Fields("Age") = Text4.Text
Adodc1.Recordset.Fields("BirthDate") = Text5.Text
Adodc1.Recordset.Fields("Address") = Text6.Text
Adodc1.Recordset.Fields("Telephone No") = Text7.Text
Adodc1.Recordset.Fields("Civil Status") = Text8.Text
Adodc1.Recordset.Fields("Date Admitted") = Text9.Text
Adodc1.Recordset.Fields("Room Type") = Text10.Text
Adodc1.Recordset.Fields("Room No.") = Text11.Text
Adodc1.Recordset.Fields("Guardian") = Text12.Text
Adodc1.Recordset.Fields("GAddress") = Text13.Text
Adodc1.Recordset.Fields("Attending Physician") = Text14.Text
Adodc1.Recordset.Update
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Text6.Enabled = False
Text7.Enabled = False
Text8.Enabled = False
Text9.Enabled = False
Text10.Enabled = False
Text11.Enabled = False
Text12.Enabled = False
Text13.Enabled = False
Text14.Enabled = False
CmdSave.Enabled = True
End if
-
April 9th, 2012, 05:43 PM
#9
Re: VB6 Save Button Command
Pretty hard without a NEW record... Come on. HELP others.
Your code omitted a line.
-
April 10th, 2012, 01:43 AM
#10
Re: VB6 Save Button Command
Hi David ,really i did not notice .
Code:
If ValidateEntries Then
Adodc1.recordset.Addnew
Adodc1.Recordset.Fields("Hospital No.") = Text1.Text
Adodc1.Recordset.Fields("Patient No.") = Text2.Text
Adodc1.Recordset.Fields("Patient Name") = Text3.Text
Adodc1.Recordset.Fields("Age") = Text4.Text
Adodc1.Recordset.Fields("BirthDate") = Text5.Text
Adodc1.Recordset.Fields("Address") = Text6.Text
Adodc1.Recordset.Fields("Telephone No") = Text7.Text
Adodc1.Recordset.Fields("Civil Status") = Text8.Text
Adodc1.Recordset.Fields("Date Admitted") = Text9.Text
Adodc1.Recordset.Fields("Room Type") = Text10.Text
Adodc1.Recordset.Fields("Room No.") = Text11.Text
Adodc1.Recordset.Fields("Guardian") = Text12.Text
Adodc1.Recordset.Fields("GAddress") = Text13.Text
Adodc1.Recordset.Fields("Attending Physician") = Text14.Text
Adodc1.Recordset.Update
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Text6.Enabled = False
Text7.Enabled = False
Text8.Enabled = False
Text9.Enabled = False
Text10.Enabled = False
Text11.Enabled = False
Text12.Enabled = False
Text13.Enabled = False
Text14.Enabled = False
CmdSave.Enabled = True
End if
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|