I have been getting Syntax error in INSERT INTO STATEMENT.
TRIED INPUTTING DIFFERENT STATEMENT. WAS UNABLE TO FIND ERROR.
NEW AT VB
THANKS IN ADVANCE.
PleasePrivate Sub cmdCreate_Click()
If CreateAccessDatabase(txtDatabaseName.Text) = False Then
MsgBox ("Database Created")
Else
MsgBox ("Database Created Failed")
End If
End Sub
'------------------------------------------------
'Set the database filename
Private Sub cmdDBName_Click()
Dim DBfile_name As String
DBfile_name = "U:\PP\2005"
If Right$(DBfile_name, 1) <> "\" Then DBfile_name = DBfile_name & "\"
DBfile_name = DBfile_name & txtPP & _
cboCounty.List(cboCounty.ListIndex) & _
cboQrt.List(cboQrt.ListIndex) & _
cboYear.List(cboYear.ListIndex) & _
".mdb"
txtDatabaseName.Text = DBfile_name
End Sub
'------------------------------------------------
Public Function CreateAccessDatabase(ByVal DatabaseFullPath As String) As Boolean
Dim bAns As Boolean
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim con As ADODB.Connection
Dim sql As String
Set cat = New ADOX.Catalog
Set tbl = New ADOX.Table
' Delete the database if it already exists.
On Error Resume Next
Kill DatabaseFullPath
On Error GoTo 0
' Create the new database.
cat.Create _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & DatabaseFullPath & ";"
' Connect to the database.
Set con = cat.ActiveConnection
bAns = True
' Create a new table.
tbl.Name = "PPR"
tbl.Columns.Append "CC", adVarWChar, 2
tbl.Columns.Append "PT", adVarWChar, 2
tbl.Columns.Append "PRO", adVarWChar, 9
tbl.Columns.Append "Name", adVarWChar, 50
tbl.Columns.Append "Address - Line 1", adVarWChar, 30
tbl.Columns.Append "Address - Line 2", adVarWChar, 30
cat.Tables.Append tbl
' Insert records.
'connect to sql
sql = "select * from " & _
"ppr_rpt1_bu"
'Set oCn = fncSetObjConnRpt
'Set oRsSql = fncSetRSOpen(fncSetObjConnRpt, sql)
con.Execute "INSERT INTO Prescriber" & oRsSql
' Close the database connection.
con.Close
SADOCLOSE OCN, ORS
Set con = Nothing
Set tbl = Nothing
Set cat = Nothing
bAns = False
End Function
'------------------------------------------------
Public Property Get sConnectToDBRpt() As String
Dim strConnect As String 'DB Connection string
strConnect = "Driver={SQL SERVER};" & _
"Server=NEW_server;" & _
"DATABASE=DB_server;" & _
"TRUSTED_CONNECTION=yes;"
sConnectToDBRpt = strConnect
End Property
'------------------------------------------------
Public Function fncSetObjConnRpt()
On Error Resume Next
Dim objCn As Object 'as ADODB.Connection
Set objCn = CreateObject("ADODB.Connection")
objCn.ConnectionString = sConnectToDBRpt
objCn.CommandTimeout = 30
objCn.CursorLocation = adUseClient '=3 AdUseServer=2
objCn.Open
If Err.Number <> 0 Then
Set objCn = Nothing 'return invalid connection object
MsgBox "Mistake on connecting: " & Err.Description
Err.Clear
End If
Set fncSetObjConnRpt = objCn
End Function
'------------------------------------------------
Public Function fncSetRSOpen(sConnRS As String, sSqlRS As String)
On Error Resume Next
Dim objRS As Object 'as ADODB.Connection
Set objRS = CreateObject("ADODB.Recordset")
objRS.CursorLocation = adUseClient '3
objRS.Open sSqlRS, sConnRS, 0, 1
If Err.Number <> 0 Then
Set objRS = Nothing
MsgBox "Not a recordset!" & Err.Description
Err.Clear
End If
Set fncSetRSOpen = objRS
End Function
'------------------------------------------------------------------
' Close Connection and Recordset
Public Sub sConnClose(objCn)
On Error Resume Next
objCn.Close
Set objCn = Nothing
Err.Clear
End Sub
'------------------------------------------------------------------
Public Sub sRSClose(objRS)
On Error Resume Next
objRS.Close
Set objRS = Nothing
Err.Clear
End Sub
'------------------------------------------------------------------
Public Sub sADOClose(objCn, objRS)
Call sConnClose(objCn)
Call sRSClose(objRS)
End Sub
'------------------------------
Thanks.
TRIED INPUTTING DIFFERENT STATEMENT. WAS UNABLE TO FIND ERROR.
NEW AT VB
THANKS IN ADVANCE.
PleasePrivate Sub cmdCreate_Click()
If CreateAccessDatabase(txtDatabaseName.Text) = False Then
MsgBox ("Database Created")
Else
MsgBox ("Database Created Failed")
End If
End Sub
'------------------------------------------------
'Set the database filename
Private Sub cmdDBName_Click()
Dim DBfile_name As String
DBfile_name = "U:\PP\2005"
If Right$(DBfile_name, 1) <> "\" Then DBfile_name = DBfile_name & "\"
DBfile_name = DBfile_name & txtPP & _
cboCounty.List(cboCounty.ListIndex) & _
cboQrt.List(cboQrt.ListIndex) & _
cboYear.List(cboYear.ListIndex) & _
".mdb"
txtDatabaseName.Text = DBfile_name
End Sub
'------------------------------------------------
Public Function CreateAccessDatabase(ByVal DatabaseFullPath As String) As Boolean
Dim bAns As Boolean
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim con As ADODB.Connection
Dim sql As String
Set cat = New ADOX.Catalog
Set tbl = New ADOX.Table
' Delete the database if it already exists.
On Error Resume Next
Kill DatabaseFullPath
On Error GoTo 0
' Create the new database.
cat.Create _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & DatabaseFullPath & ";"
' Connect to the database.
Set con = cat.ActiveConnection
bAns = True
' Create a new table.
tbl.Name = "PPR"
tbl.Columns.Append "CC", adVarWChar, 2
tbl.Columns.Append "PT", adVarWChar, 2
tbl.Columns.Append "PRO", adVarWChar, 9
tbl.Columns.Append "Name", adVarWChar, 50
tbl.Columns.Append "Address - Line 1", adVarWChar, 30
tbl.Columns.Append "Address - Line 2", adVarWChar, 30
cat.Tables.Append tbl
' Insert records.
'connect to sql
sql = "select * from " & _
"ppr_rpt1_bu"
'Set oCn = fncSetObjConnRpt
'Set oRsSql = fncSetRSOpen(fncSetObjConnRpt, sql)
con.Execute "INSERT INTO Prescriber" & oRsSql
' Close the database connection.
con.Close
SADOCLOSE OCN, ORS
Set con = Nothing
Set tbl = Nothing
Set cat = Nothing
bAns = False
End Function
'------------------------------------------------
Public Property Get sConnectToDBRpt() As String
Dim strConnect As String 'DB Connection string
strConnect = "Driver={SQL SERVER};" & _
"Server=NEW_server;" & _
"DATABASE=DB_server;" & _
"TRUSTED_CONNECTION=yes;"
sConnectToDBRpt = strConnect
End Property
'------------------------------------------------
Public Function fncSetObjConnRpt()
On Error Resume Next
Dim objCn As Object 'as ADODB.Connection
Set objCn = CreateObject("ADODB.Connection")
objCn.ConnectionString = sConnectToDBRpt
objCn.CommandTimeout = 30
objCn.CursorLocation = adUseClient '=3 AdUseServer=2
objCn.Open
If Err.Number <> 0 Then
Set objCn = Nothing 'return invalid connection object
MsgBox "Mistake on connecting: " & Err.Description
Err.Clear
End If
Set fncSetObjConnRpt = objCn
End Function
'------------------------------------------------
Public Function fncSetRSOpen(sConnRS As String, sSqlRS As String)
On Error Resume Next
Dim objRS As Object 'as ADODB.Connection
Set objRS = CreateObject("ADODB.Recordset")
objRS.CursorLocation = adUseClient '3
objRS.Open sSqlRS, sConnRS, 0, 1
If Err.Number <> 0 Then
Set objRS = Nothing
MsgBox "Not a recordset!" & Err.Description
Err.Clear
End If
Set fncSetRSOpen = objRS
End Function
'------------------------------------------------------------------
' Close Connection and Recordset
Public Sub sConnClose(objCn)
On Error Resume Next
objCn.Close
Set objCn = Nothing
Err.Clear
End Sub
'------------------------------------------------------------------
Public Sub sRSClose(objRS)
On Error Resume Next
objRS.Close
Set objRS = Nothing
Err.Clear
End Sub
'------------------------------------------------------------------
Public Sub sADOClose(objCn, objRS)
Call sConnClose(objCn)
Call sRSClose(objRS)
End Sub
'------------------------------
Thanks.