0
현재 Excel VBA를 사용하여 서비스 시스템 응용 프로그램을 만들고 있습니다. 입력 양식을 얻으려면 userform이 있고 일부 Microsoft Access 테이블에 가져 오기 데이터를 저장하고 싶습니다.Microsoft Excel에서 VBA를 사용하여 Excel에서 Excel로 데이터 내보내기 오류
userform에서 데이터를 가져 와서 액세스 테이블에 입력하려고합니다.이 코드를 실행하면 구문 오류가 발생합니다. 제발 당신 도움이 필요해.
Public Sub AddDatabaseEntry()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim stDB As String, stSQL As String, stProvider As String
Dim Name As String
Dim Address As String
Name = TextBox1
Address = TextBox2
stDB = "Data Source= " & ThisWorkbook.Path & "\SERVDB.accdb"
stProvider = "Microsoft.ACE.OLEDB.12.0"
'Opening connection to database
With cn
.ConnectionString = stDB
.Provider = stProvider
.Open
End With
'SQL Statement of what I want from the database
stSQL = "INSERT INTO Client (FullName, Address) " & _
"Values (" & Name & ", " & Address & ")"
cn.Execute stSQL
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
Private Sub CommandButton2_Click()
AddDatabaseEntry
End Sub
에서 예약어로, 당신의 'NAME'뭔가 다른 에 변수를 변경하는 것이 매우 권할 귀하의 삽입. [명령을 매개 변수화하는] 것이 더 좋습니다 (http://stackoverflow.com/documentation/vba/3578/working-with-ado/12354/creating-parametrized-commands). – Comintern
구문 오류에 대한 세부 정보를 추가하십시오. –