Question
-
Topic
-
explain the code
LockedI need some one hellp me to understand this code ,so I could add an option button and check box
Private Sub CommandButton1_Click()
Dim cnn As ADODB.Connection
Dim strConnection As String
Dim strSQL, strsql2 As String
Dim strPath As String
Dim doc As Word.Document
Dim strCompanyName As String
Dim strPhone As String
Dim strtext1 As String
Dim strname2, strphone2 As String
Dim bytContinue As Byte
Dim lngSuccess, lngSuccess2 As Long
Set doc = ThisDocument
On Error GoTo ErrHandler
strCompanyName = Chr(39) & doc.FormFields(“txtCompanyName”).Result & Chr(39)
strPhone = Chr(39) & doc.FormFields(“txtPhone”).Result & Chr(39)
strtext1 = Chr(39) & doc.FormFields(“Text1”).Result & Chr(39)
strname2 = Chr(39) & doc.FormFields(“txtname2”).Result & Chr(39)
strphone2 = Chr(39) & doc.FormFields(“txtphone2”).Result & Chr(39)bytContinue = MsgBox(“Do you want to insert this record?”, vbYesNo, “Add Record”)
If bytContinue = vbYes Then
strSQL = “INSERT INTO Shippers(CompanyName, Phone,text1) VALUES (” & strCompanyName & “,” & strPhone & “,” & strtext1 & “)”
strsql2 = “INSERT INTO part2(name2,phone2)VALUES(” & strname2 & “,” & strphone2 & “)”strPath = “D:\nor.mdb”
strConnection = “Provider=Microsoft.Jet.OLEDB.4.0;” & “Data Source = ” & strPath
Set cnn = New ADODB.Connection
With cnn
.Provider = “Microsoft.Jet.OLEDB.4.0”
.Properties(“Data Source”).Value = strPath
.Open strConnection
End With
cnn.Execute strSQL, lngSuccess
cnn.Execute strsql2, lngSuccess2
cnn.Close
doc.FormFields(“txtCompanyName”).TextInput.Clear
doc.FormFields(“txtPhone”).TextInput.Clear
doc.FormFields(“Text1”).TextInput.Clear
doc.FormFields(“txtname2”).TextInput.Clear
doc.FormFields(“txtphone2”).TextInput.Clear
End If
Set doc = Nothing
Set cnn = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Number & “: ” & Err.Description, vbOKOnly, “Error”
On Error GoTo 0
On Error Resume Next
Set doc = Nothing
Set cnn = NothingEnd Sub