Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 57
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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 57
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.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Another IF statement question Valerie Excel Worksheet Functions 1 April 21st 09 12:01 AM
IF - And - Then Statement question MayJuneJuly Excel Worksheet Functions 4 September 19th 08 04:00 PM
If then statement question.... atlcasework New Users to Excel 7 January 14th 08 06:37 PM
If statement question ranvin56 Excel Discussion (Misc queries) 2 December 12th 07 12:41 AM
IF statement question [email protected] Excel Worksheet Functions 2 July 24th 06 04:20 PM


All times are GMT +1. The time now is 09:00 PM.

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

About Us

"It's about Microsoft Excel"