A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

SQL statement question



 
 
Thread Tools Display Modes
  #1  
Old November 19th, 2009, 01:02 PM posted to microsoft.public.excel.misc
gab1972
external usenet poster
 
Posts: 7
Default SQL statement question

Someone please help with this coding. I'm getting a data mismatch
error.

Dim cn As ADODB.Connection
Dim str As String
Dim sql As String
Dim lRecords As Long
Dim rs As ADODB.Recordset
Dim wbBook As Workbook
Dim wsSheet1 As Worksheet
Dim pNum As String
Dim cl As String
Dim oldP As Date

Set wbBook = ThisWorkbook
Set wsSheet1 = wbBook.Worksheets("Holding")
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset


' connect to the Access database
'Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=Z:\COMMON FILES\Encroachment Permits\Permit.Tracker
\Database\Permit.Tracker.mdb;"



str = "SELECT Min(permit_log_date) AS Minofpermit_log_date FROM
permit_info WHERE curr_location '" & cl & "'" 'original working
line
'str = "SELECT permit_num AS Minofpermit_log_date FROM permit_info"
'testing line
rs.Open str, cn ', adOpenKeyset ', adLockOptimistic
With wsSheet1
.Cells(3, 6).CopyFromRecordset rs
End With
oldP = Sheets("Holding").Range("F3").Value
rs.Close
str = "SELECT permit_num FROM permit_info WHERE permit_log_date = '" &
oldP & "'"
rs.Open str, cn, adOpenKeyset, adLockOptimistic 'GETTING ERROR ON
THIS LINE
'Sheets("Report.Card").Range("G7").CopyFromRecords et rs
Sheets("Holding").Range("A3").CopyFromRecordset rs

Fin:
ActiveWorkbook.Sheets("Report.Card").Protect
Application.ScreenUpdating = True
End Sub
  #2  
Old November 19th, 2009, 04:38 PM posted to microsoft.public.excel.misc
mike
external usenet poster
 
Posts: 3,942
Default SQL statement question

Try this
#" & oldP & "#"

"gab1972" wrote:

Someone please help with this coding. I'm getting a data mismatch
error.

Dim cn As ADODB.Connection
Dim str As String
Dim sql As String
Dim lRecords As Long
Dim rs As ADODB.Recordset
Dim wbBook As Workbook
Dim wsSheet1 As Worksheet
Dim pNum As String
Dim cl As String
Dim oldP As Date

Set wbBook = ThisWorkbook
Set wsSheet1 = wbBook.Worksheets("Holding")
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset


' connect to the Access database
'Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=Z:\COMMON FILES\Encroachment Permits\Permit.Tracker
\Database\Permit.Tracker.mdb;"



str = "SELECT Min(permit_log_date) AS Minofpermit_log_date FROM
permit_info WHERE curr_location '" & cl & "'" 'original working
line
'str = "SELECT permit_num AS Minofpermit_log_date FROM permit_info"
'testing line
rs.Open str, cn ', adOpenKeyset ', adLockOptimistic
With wsSheet1
.Cells(3, 6).CopyFromRecordset rs
End With
oldP = Sheets("Holding").Range("F3").Value
rs.Close
str = "SELECT permit_num FROM permit_info WHERE permit_log_date = '" &
oldP & "'"
rs.Open str, cn, adOpenKeyset, adLockOptimistic 'GETTING ERROR ON
THIS LINE
'Sheets("Report.Card").Range("G7").CopyFromRecords et rs
Sheets("Holding").Range("A3").CopyFromRecordset rs

Fin:
ActiveWorkbook.Sheets("Report.Card").Protect
Application.ScreenUpdating = True
End Sub
.

  #3  
Old November 19th, 2009, 09:42 PM posted to microsoft.public.excel.misc
gab1972
external usenet poster
 
Posts: 7
Default SQL statement question

On Nov 19, 11:38*am, Mike wrote:
Try this
#" & oldP & "#"



"gab1972" wrote:
Someone please help with this coding. *I'm getting a data mismatch
error.


Dim cn As ADODB.Connection
Dim str As String
Dim sql As String
Dim lRecords As Long
Dim rs As ADODB.Recordset
Dim wbBook As Workbook
Dim wsSheet1 As Worksheet
Dim pNum As String
Dim cl As String
Dim oldP As Date


Set wbBook = ThisWorkbook
Set wsSheet1 = wbBook.Worksheets("Holding")
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset


' connect to the Access database
'Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=Z:\COMMON FILES\Encroachment Permits\Permit.Tracker
\Database\Permit.Tracker.mdb;"


str = "SELECT Min(permit_log_date) AS Minofpermit_log_date FROM
permit_info WHERE curr_location '" & cl & "'" 'original working
line
'str = "SELECT permit_num AS Minofpermit_log_date FROM permit_info"
'testing line
rs.Open str, cn ', adOpenKeyset ', adLockOptimistic
With wsSheet1
* * * * .Cells(3, 6).CopyFromRecordset rs
End With
oldP = Sheets("Holding").Range("F3").Value
rs.Close
str = "SELECT permit_num FROM permit_info WHERE permit_log_date = '" &
oldP & "'"
rs.Open str, cn, adOpenKeyset, adLockOptimistic *'GETTING ERROR ON
THIS LINE
'Sheets("Report.Card").Range("G7").CopyFromRecords et rs
Sheets("Holding").Range("A3").CopyFromRecordset rs


Fin:
ActiveWorkbook.Sheets("Report.Card").Protect
Application.ScreenUpdating = True
End Sub
.


THANK YOU THANK YOU THANK YOU THANK YOU!!! That worked. I NEVER
would have guessed something like that. Thanks for all your help.
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:18 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.