Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 26th, 2005, 03:14 PM
Authorized User
 
Join Date: Feb 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to chacquard
Default Need help with a query to add records

Hi,

I have a query that adds records to a table. I need to run this query several times, each time with a specific criteria. For example, i need to run it when field1 = "A"; then I need to run it when field2 = "B"... and so on.

Now I have two questions:

1) In VB, how can I reuse the same query with a criteria instead of creating 26 queries?

2) In VB, how can I increment the criteria value ("A" to "B", to "C", etc.)

Thank you !

Chantal

 
Old February 28th, 2005, 04:23 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Hi,

   This can be easily done. I need to know more about table structure and the query. When will these queries be done? With user input on a form, or automatically at some point according to the time of day, etc?

   To get you started, you can do this if you are passing a value from a combo box or text box to a query (I use this for 180 different parameters to make reports in a database using one query and one report):

'==========

   Dim stQueryName As String
   Dim stLink As String
   Dim stPassedValue As String

   stPassedValue = Me.YourComboOrTextBox.Value

   stLink = "[QueryParameterField] = " & "'" & stPassedValue & "'"

   stQueryName = "qryYourQueryName"
   DoCmd.Etc...
'==========

   If the user clicks a button to start this process, put this on the button's On Click event, and then it passes whatever value is in your text or combo box.

   NOTE ON COMBO BOXES: Make sure they are bound to the column that has the value you want to pass. Otherwise it will pass the PK, and not the meaningful value (Column 1 is the default). Text boxes won't be a problem.

HTH



mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Add records with VBA rohit_ghosh Access VBA 2 June 22nd, 2007 04:13 AM
how to know who edit or add records? drachx General .NET 1 October 13th, 2004 05:36 AM
how to know who edit add records? drachx SQL Server 2000 9 October 13th, 2004 04:28 AM
Add records from a Datagrid dkomo VB.NET 0 May 6th, 2004 01:08 PM
How to add records hdvan SQL Server ASP 2 September 24th, 2003 12:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.