Run-time Error 2342

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a problem with Run-time error number 2342.
I think my sqlCmd statement is correct, but I have on idea, how can I solve
this problem whe running application with statement below:

Dim tBatchNum As String
tBatchNum = Me.Batch_Number

sqlCmd = "SELECT [Batch Number], Items " _
& "FROM Table1 " _
& "WHERE [Batch Number]= '" & tBatchNum & "';"

DoCmd.RunSQL sqlCmd

And then I would like to show it on TextBox. I give the name of textbox is
Items.
Then

Items.Value = Items

Anyways, how can I solve the problem that occur when running this application.

Art
 
The RunSQL you use for Action queries such as Insert, Delete, Update, Create.

To open a slect query, try

sqlCmd = "SELECT [Batch Number], Items " _
& "FROM Table1 " _
& "WHERE [Batch Number]= '" & tBatchNum & "';"

DoCmd.OpenQuery sqlCmd
 
I don't believe that'll work, Ofer.

OpenQuery expects the name of a query, not an SQL string.

I think it's necessary to create a named QueryDef object and then open it:

Dim qdfCurr As DAO.QueryDef
Dim txtSQL As String

txtSQL = "SELECT [Batch Number], Items " _
& "FROM Table1 " _
& "WHERE [Batch Number]= '" & tBatchNum

Set qdfCurr = CurrentDb.CreateQueryDef("Temp", txtSQL)
DoCmd.OpenQuery "Temp"
CurrentDB.QueryDefs.Delete "Temp"

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Ofer Cohen said:
The RunSQL you use for Action queries such as Insert, Delete, Update,
Create.

To open a slect query, try

sqlCmd = "SELECT [Batch Number], Items " _
& "FROM Table1 " _
& "WHERE [Batch Number]= '" & tBatchNum & "';"

DoCmd.OpenQuery sqlCmd
--
Good Luck
BS"D


March said:
I have a problem with Run-time error number 2342.
I think my sqlCmd statement is correct, but I have on idea, how can I
solve
this problem whe running application with statement below:

Dim tBatchNum As String
tBatchNum = Me.Batch_Number

sqlCmd = "SELECT [Batch Number], Items " _
& "FROM Table1 " _
& "WHERE [Batch Number]= '" & tBatchNum & "';"

DoCmd.RunSQL sqlCmd

And then I would like to show it on TextBox. I give the name of textbox
is
Items.
Then

Items.Value = Items

Anyways, how can I solve the problem that occur when running this
application.

Art
 
Ooops, I should have noticed that.
Thanks Douglas

--
Good Luck
BS"D


Douglas J. Steele said:
I don't believe that'll work, Ofer.

OpenQuery expects the name of a query, not an SQL string.

I think it's necessary to create a named QueryDef object and then open it:

Dim qdfCurr As DAO.QueryDef
Dim txtSQL As String

txtSQL = "SELECT [Batch Number], Items " _
& "FROM Table1 " _
& "WHERE [Batch Number]= '" & tBatchNum

Set qdfCurr = CurrentDb.CreateQueryDef("Temp", txtSQL)
DoCmd.OpenQuery "Temp"
CurrentDB.QueryDefs.Delete "Temp"

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Ofer Cohen said:
The RunSQL you use for Action queries such as Insert, Delete, Update,
Create.

To open a slect query, try

sqlCmd = "SELECT [Batch Number], Items " _
& "FROM Table1 " _
& "WHERE [Batch Number]= '" & tBatchNum & "';"

DoCmd.OpenQuery sqlCmd
--
Good Luck
BS"D


March said:
I have a problem with Run-time error number 2342.
I think my sqlCmd statement is correct, but I have on idea, how can I
solve
this problem whe running application with statement below:

Dim tBatchNum As String
tBatchNum = Me.Batch_Number

sqlCmd = "SELECT [Batch Number], Items " _
& "FROM Table1 " _
& "WHERE [Batch Number]= '" & tBatchNum & "';"

DoCmd.RunSQL sqlCmd

And then I would like to show it on TextBox. I give the name of textbox
is
Items.
Then

Items.Value = Items

Anyways, how can I solve the problem that occur when running this
application.

Art
 
Back
Top