docmd.runsql help required 
Author Message
 docmd.runsql help required

I am trying to write an access database (my first) to catalogue the
computers, and their software at work.
I have a form to remove software from the repository when it is no longer
needed, using 3 combo boxes, which are fed by SELECT DISTINCT queries based
on earlier choices.
Once I have chosen the Manufacturer, Product & Version, I click on the OK
button which triggers the following VBA code...

DoCmd.RunSQL "DELETE FROM tbl_software WHERE manufacturer =
cmb_manufacturer.Text AND product = cmb_product.Text AND version =
cmb_version.Text;"

This always says that it is going to delete 0 records.  I want to know if
anyone has any idea why.  If I run the same SQL code, but alter the cmb_*
combo box references, it prompts me for the details, and if I enter them, it
will delete 1 record.  Why will it not pick up the .Text from the combo
boxes?

Thanks in advance for any help,

Andy Jeffrey



Sun, 15 Aug 2004 17:58:57 GMT  
 docmd.runsql help required

Quote:

> I am trying to write an access database (my first) to catalogue the
> computers, and their software at work.
> I have a form to remove software from the repository when it is no longer
> needed, using 3 combo boxes, which are fed by SELECT DISTINCT queries based
> on earlier choices.
> Once I have chosen the Manufacturer, Product & Version, I click on the OK
> button which triggers the following VBA code...

> DoCmd.RunSQL "DELETE FROM tbl_software WHERE manufacturer =
> cmb_manufacturer.Text AND product = cmb_product.Text AND version =
> cmb_version.Text;"

> This always says that it is going to delete 0 records.  I want to know if
> anyone has any idea why.  If I run the same SQL code, but alter the cmb_*
> combo box references, it prompts me for the details, and if I enter them, it
> will delete 1 record.  Why will it not pick up the .Text from the combo
> boxes?

> Thanks in advance for any help,

> Andy Jeffrey

Where using SQL in code like this you need to build the string using the
combo boxes values like this:

DoCmd.RunSQL "DELETE FROM tbl_software WHERE manufacturer = """ & _

        cmb_manufacturer & """ AND product = """ & _

        cmb_product & """ AND version = """ & cmb_version & """"

Note the extra " in the string, using "" will preserve the little value
of the " in your string (assuming all the required fields are text, if
they're numbers then the quotes aren't required.).

The above string translates as:

DELETE FROM tbl_software WHERE manufacturer = "someManufacturer" AND
product = "someProduct" AND Version = "someVersion"

for all numeric values use:

DoCmd.RunSQL "DELETE FROM tbl_software WHERE manufacturer = & _
        cmb_manufacturer & " AND product = " & _
        cmb_product & " AND version = " & cmb_version

--
Hope this helps
Tony Oakley (MVP)



Sun, 15 Aug 2004 19:39:37 GMT  
 docmd.runsql help required
Thanks for that Tony.

Now I get a Runtime Error '2185'...
You can't reference a property or method for a control unless the control
has the focus.
The help button is greyed out, and searching the knowledge base returns no
entries for this error number...any ideas.



Sun, 15 Aug 2004 20:02:10 GMT  
 docmd.runsql help required
You'll notice that Tony's code did NOT reference the .text property.  
You need to reference the .Value property.  Tony's code did that since
the default property is the .Value property.

The Text property in Access only exists while a control has the focus
and data is being entered/changed in the control.

Quote:

> Thanks for that Tony.

> Now I get a Runtime Error '2185'...
> You can't reference a property or method for a control unless the control
> has the focus.
> The help button is greyed out, and searching the knowledge base returns no
> entries for this error number...any ideas.



Sun, 15 Aug 2004 21:23:05 GMT  
 docmd.runsql help required
You cannot reference the Text Property of the Control unless it has the
Focus.  In you case, you referenced the Text Property of 3 different
Controls and only ONE Control can have the Focus at any time.

Try the Value Property instead.  Since the Value Property is normally the
Default Property, you can omit ".Value" altogether.

HTH
Van T. Dinh


Quote:
> Thanks for that Tony.

> Now I get a Runtime Error '2185'...
> You can't reference a property or method for a control unless the control
> has the focus.
> The help button is greyed out, and searching the knowledge base returns no
> entries for this error number...any ideas.



Sun, 15 Aug 2004 21:29:19 GMT  
 docmd.runsql help required
Thanks for that...all sorted now...appreciate the help...Andy


Sun, 15 Aug 2004 23:20:50 GMT  
 docmd.runsql help required
Thanks for that...all sorted now...appreciate the help...Andy


Sun, 15 Aug 2004 23:20:39 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. DoCmd.RunSql - Need help please!

2. DoCmd.RunSQL

3. DoCmd.RunSQL Error

4. DoCmd.RunSQL error 2

5. docmd.RunSql problem

6. docmd.RunSQL String Concatenation

7. DoCmd.RunSQL too long record

8. DoCmd.RunSQL

9. suppress warnings on DoCmd.RunSQL ?

10. docmd.runsql repeat problem

11. DoCmd.RunSQL vs. Recordsets

12. docmd.runSQL fails on Windows 2000

 

 
Powered by phpBB® Forum Software