CodePudding user response:
Private Sub Command1_Click () on a
'Adodc1. You. MovePrevious
If Adodc1. You. BOF Then
Adodc1. You. MoveFirst
MsgBox "has to first!" , vbOKOnly
End the If
End Sub
Private Sub Command2_Click () 'the next
Adodc1. You. MoveNext
EOF Then If Adodc1. You.
Adodc1. You. AddNew
End the If
If Len (Text1. Text)=0 And Len (Text2. Text)=0 And Len (Text1. Text)=0 Then
Command1. Enabled=False
Command2. Enabled=False
End the If
Text1. SetFocus
End Sub
Private Sub Command3_Click new
() 'Adodc1. RecordSource="select * from li13241214"
Adodc1. Refresh
End Sub
Private Sub Command4_Click () 'delete
SendKeys vbKeyDelete
End Sub
Private Sub Command5_Click () 'save
If Len (Text1. Text)=0 Then
MsgBox "code cannot be empty!" , vbOKOnly
The Else
Adodc1. You. Update
Command1. Enabled=True
Command2. Enabled=True
Et. The Update
X=0
End Sub
Private Sub Command6_Click () 'exit
Adodc1. You. CancelUpdate
Unload Me
End Sub
Private Sub Form_Load ()
Adodc1. RecordSource="select * from li13241214"
Adodc1. Refresh
Text1. Text=""
Text2. Text=""
Text3. Text=""
Text4. Text=""
If Adodc1. You. RecordCount & gt; 0 Then
Text1. Text=Adodc1. You. Fields (" code ")
Text2. Text=Adodc1. You. Fields (" name ")
Text3. Text=Adodc1. You. Fields (" mileage ")
Text4. Text=Adodc1. You. Fields (" note ")
End the If
X=0
End Sub
CodePudding user response:
Were six command, 1-6 are respectively on the condition that the next article, add, delete, save and quit,Because can't upload pictures, can't, strives for the great god answer, thank you,,
CodePudding user response:
In the first place in the general section of the form declare two variables with a dynamic arrayDim KK As Long, SID () As Long, XX As Integer
In the form of variables in the event of start XX array with SID assignment
Private Sub Form_Load ()
Adodc1. The ConnectionString="Provider=Microsoft. Jet. The OLEDB. 4.0; Data Source="& amp; App. The Path & amp; "\ information table. MDB. Persist Security Info=False "
Adodc1. RecordSource="Select * From coach information", "
Adodc1. Refresh
XX=Adodc1. You. RecordCount 'total data table records
ReDim SID To XX (1) 'for an array subscript
The Do While Not Adodc1. You. EOF
I=I + 1
SID (I)=Adodc1. You. Fields (" ID ") 'SID to array assignment, it is all the records of the ID, the ID field is the automatic numbering field
Adodc1. You. MoveNext
Loop
KK=1 'KK to variable initial
End Sub
I'm sorry, have something to go out, I'll give you other code,
CodePudding user response:
Under a code, KK is the variable test records, SID (KK) is the record ID, only detect specific records, can be displayed, in a like under a basic, is nothing more than KK=KK - 1,Private Sub Command2_Click ()
Under a
'KK=KK + 1
If KK & gt; XX: XX Then KK=MsgBox "is the last one!"
Adodc1. RecordSource="Select * From coach information Where ID=" & amp; SID (KK) & amp; "
"'SID (KK) is documented ID number, so you can query to the record
Adodc1. Refresh
Text1. Text=Adodc1. You. Fields (" number ")
Text2. Text=Adodc1. You. Fields (" name ")
Text3. Text=Adodc1. You. Fields (" mileage ")
Text4. Text=Adodc1. You. Fields (" note ")
End Sub
New records of the HTML code is as follows, modify records with the new basic same, but different SQL statements, should be the Where ID="& amp; SID (KK) & amp; "Because change is need to modify the record,
Private Sub Command3_Click ()
New
'If MsgBox (" do you want to add a message?" , 33, "the new confirm!" )=1 Then
If Text1. Text="" Then
MsgBox "you no input serial number, please enter!"
The Exit Sub
End the If
If Text2. Text="" Then
MsgBox "you didn't input the name, please enter!"
The Exit Sub
End the If
If Text3. Text="" Then
MsgBox "you no input, please input!"
The Exit Sub
End the If
If Text4. Text="" Then
MsgBox "you no input remark, please enter!"
The Exit Sub
End the If
Adodc1. RecordSource="Select * From coach information Where id='" & amp; Text1. Text & amp; "' or the name=" & amp; Text2. Text & amp; "'
"Adodc1. Refresh
EOF=True Then the If Adodc1. You. 'If Adodc1. You. EOF=True, the number and the name of the same record does not exist, you can add,
Adodc1. You. AddNew
Adodc1. You. Fields (" id ")=Text1. Text
Adodc1. You. Fields (" name ")=Text2. Text
Adodc1. You. Fields (" mileage ")=Text3. Text
Adodc1. You. Fields (" note ")=Text4. Text
Adodc1. You. Update
MsgBox "congratulations! A message successfully added!"
Unload Me
Form1. Show
Else 'if Adodc1. You. EOF=False, serial number and the name of the same record, not new,
MsgBox "sorry! This message already exists, you can not add again!"
Text1. Text=""
Text2. Text=""
Text3. Text=""
Text4. Text="" 'will empty Text box, so that once again add
End the If
End the If
End Sub
Finally, delete records, delete records and modification of SQL statements system
Private Sub Command4_Click ()
'delete
If MsgBox (" do you really want to delete this message?" , 33, remove confirmed! "" )=1 Then
Adodc1. RecordSource="Select * From coach information Where ID=" & amp; SID (KK) & amp; "
"Adodc1. Refresh
Adodc1. You. Delete
MsgBox "congratulations! This message deleted successfully!"
Unload Me
Form1. Show
End the If
End Sub
Below is the interface: you modify for your database, it is ok to change on the field names,nullnull