i am attempting to run some sql from within VB that selects from an access table. The use selects which records they would like by entering the range of numbers into text boxes, i have used the following sql statement:
Private Sub cmdPrint_Click()
Dim AccessApp As Access.Application
Dim DBPath As String
Dim no1, no2 As Long
no1 = txtFrom1.Text
no2 = txtTo1.Text
DBPath = "C:\My Documents\darryl.mdb"
Set AccessApp = New Access.Application
With AccessApp
.OpenCurrentDatabase DBPath
.DoCmd.RunSQL ("ALTER TABLE LetterSelection ADD [Seq_no] Counter"
.DoCmd.RunSQL ("Select * into output from LetterSelection where Seq_no between '" & no1 & " ' and '" & no2 & "'"
.CloseCurrentDatabase
End With
End Sub
I am getting a "Data type mismatch in criteria expression" error and the debug points to the "select *..." line. I have checked the layout of the table (after the new column has been added) and the format of Seq_no is Long, so i am not sure what the problem is.
Private Sub cmdPrint_Click()
Dim AccessApp As Access.Application
Dim DBPath As String
Dim no1, no2 As Long
no1 = txtFrom1.Text
no2 = txtTo1.Text
DBPath = "C:\My Documents\darryl.mdb"
Set AccessApp = New Access.Application
With AccessApp
.OpenCurrentDatabase DBPath
.DoCmd.RunSQL ("ALTER TABLE LetterSelection ADD [Seq_no] Counter"
.DoCmd.RunSQL ("Select * into output from LetterSelection where Seq_no between '" & no1 & " ' and '" & no2 & "'"
.CloseCurrentDatabase
End With
End Sub
I am getting a "Data type mismatch in criteria expression" error and the debug points to the "select *..." line. I have checked the layout of the table (after the new column has been added) and the format of Seq_no is Long, so i am not sure what the problem is.