Solved

Referring to a text box on my Access form

Posted on 2011-02-18
5
1,115 Views
Last Modified: 2012-05-11
Using the event procedure below which executes a pass through query how would i tell the query to delete the record which is showing in a text box on my form. Usually i would use something like = Forms![DeleteImages]![CheckA but that doesn't work in this instance.
The form's name is DeleteImages and the text box name is CheckA.  

Dim dbs As Database
Dim qdfPassThrough As QueryDef
Dim qdfTemp As QueryDef

Set dbs = CurrentDb()

Set qdfPassThrough = dbs.CreateQueryDef("DeleteFormA")

qdfPassThrough.Connect = _
"ODBC;DSN=NewEis1;Description=NewEis1;APP=2007 Microsoft Office system;DATABASE=EIS;Trusted_Connection=Yes;TABLE=dbo.SCANFORMA"


qdfPassThrough.SQL = "DELETE * FROM SCANFORMA WHERE SCANFORMA.IMAGE = '000000006467'"

qdfPassThrough.ReturnsRecords = No

qdfPassThrough.Execute

dbs.QueryDefs.Delete "DeleteFormA"
dbs.Close
    'delete object variable
Set dbs = Nothing
0
Comment
Question by:restockett
  • 3
5 Comments
 
LVL 33

Expert Comment

by:jppinto
ID: 34929525
Did you've tryed like this?

= Forms![DeleteImages]![CheckA].Text
0
 
LVL 28

Expert Comment

by:omgang
ID: 34929545
Dim dbs As Database
Dim qdfPassThrough As QueryDef
Dim qdfTemp As QueryDef
Dim strCriteria As String

Set dbs = CurrentDb()

Set qdfPassThrough = dbs.CreateQueryDef("DeleteFormA")

qdfPassThrough.Connect = _
"ODBC;DSN=NewEis1;Description=NewEis1;APP=2007 Microsoft Office system;DATABASE=EIS;Trusted_Connection=Yes;TABLE=dbo.SCANFORMA"

strCriteria = Me.CheckA

'qdfPassThrough.SQL = "DELETE * FROM SCANFORMA WHERE SCANFORMA.IMAGE = '000000006467'"
'qdfPassThrough.SQL = "DELETE * FROM SCANFORMA WHERE SCANFORMA.IMAGE = " & Chr(34) & strCriteria & Chr(34)

qdfPassThrough.ReturnsRecords = No

qdfPassThrough.Execute

dbs.QueryDefs.Delete "DeleteFormA"
dbs.Close
    'delete object variable
Set dbs = Nothing

OM Gang
0
 
LVL 28

Expert Comment

by:omgang
ID: 34929560
Sorry, should have removed the comment
'qdfPassThrough.SQL = "DELETE * FROM SCANFORMA WHERE SCANFORMA.IMAGE = '000000006467'"
qdfPassThrough.SQL = "DELETE * FROM SCANFORMA WHERE SCANFORMA.IMAGE = " & Chr(34) & strCriteria & Chr(34)


Note that you could just also do
qdfPassThrough.SQL = "DELETE * FROM SCANFORMA WHERE SCANFORMA.IMAGE = " & Chr(34) & Me.CheckA & Chr(34)

OM Gang
0
 

Author Comment

by:restockett
ID: 34929921
I got an odbc --call failed error when i use the code you suggested

also is Chr(34) a bracket?  or an appostrophe?
0
 
LVL 28

Accepted Solution

by:
omgang earned 250 total points
ID: 34930015
Chr(34) is a quotation mark, e.g. "
I should have used an apostrophe (silly me).
qdfPassThrough.SQL = "DELETE * FROM SCANFORMA WHERE SCANFORMA.IMAGE = " & Chr(39) & strCriteria & Chr(39)
OM Gang
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question