Solved

Referring to a text box on my Access form

Posted on 2011-02-18
5
1,112 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now