473,765 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with macro to run lookup query twice with one prompt

1 New Member
I want to do a lookup query and append the record to a history table before editing the data.

I created a macro to run the lookup query to append the record to history and it works fine. I did the same with the lookup query that allows the user to edit the record. I then converted them to vb and combined them. Code follows.

My thinking is to create a variable dim keyno longint
then pass keyno to the lookup queries.

I am kind of new to this how do I pass keyno to the queries?

vb script follows:

Expand|Select|Wrap|Line Numbers
  1. Function mcrtest()
  2.  
  3. On Error GoTo mcrtest_Err
  4.  
  5.     DoCmd.OpenQuery "qryAppend PersonInfo Key Number Lookup to PersonHistory", acViewNormal, acEdit
  6.     DoCmd.OpenForm "frmPersonInfo Lookup Person Key with Key Number", acNormal, "", "", , acNormal
  7.  
  8. mcrtest_Exit:
  9.     Exit Function
  10.  
  11. mcrtest_Err:
  12.     MsgBox Error$
  13.     Resume mcrtest_Exit
  14.  
  15. End Function
  16.  
The sql for the append query that follows runs the lookup query below.

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tblPersonHistory
  2. SELECT [qryPersonInfo Key Number Lookup].*
  3. FROM [qryPersonInfo Key Number Lookup];
  4.  
The lookup query is

Expand|Select|Wrap|Line Numbers
  1. SELECT tblPersonInfo.[Key Number], tblPersonInfo.[Employee Number], tblPersonInfo.[First Name], tblPersonInfo.[Middle Initial], tblPersonInfo.[Last Name], tblPersonInfo.Department, tblPersonInfo.Active, tblPersonInfo.[Date of Change], tblPersonInfo.[Previous Change Date], tblPersonInfo.Notes, tblPersonInfo.Initials
  2. FROM tblPersonInfo
  3. WHERE (((tblPersonInfo.[Key Number])=[Enter the Key Number:]));
  4.  
The nuts & bolts of the question is How do I pass keyno to the query rather than having Access prompt for from the where statement?

Thanks in advance.
Joe
Mar 12 '09 #1
1 2288
DonRayner
489 Recognized Expert Contributor
Assuming you are using the keyno variable as mentioned, create a function like this.
Expand|Select|Wrap|Line Numbers
  1. Public Function KeyNumber() as long
  2.     KeyNumber = keyno
  3. End Function
Then change line 3 of your lookup query to this
Expand|Select|Wrap|Line Numbers
  1. WHERE (((tblPersonInfo.[Key Number])=KeyNumber()));

Or if the original form is still open you could just change the line 3 to this
Expand|Select|Wrap|Line Numbers
  1. WHERE (((tblPersonInfo.[Key Number])=Forms!FormName!FieldName));
With FormName and FieldName replaced with the name of the form and field that contains your key number.
Mar 14 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2764
by: Colin | last post by:
In access 2000 I need to filter records in a Subform by pushing a button on a command button located on the Main form. The Main form is blank. Its only purpose is to contain the subform which is in a datasheet format. So far… 1)I have created a query called "CatFilterQuery" which results in a prompt to enter the "category field" to filter on. 2)Created a macro called "FilterCategory" which is based on the query mentioned above and uses...
1
2636
by: Randy | last post by:
Access= 2002 I'm NOT a Programmer, but I have used VB in the past to do some things ( Spaghetti Code King) so I have some understanding of Coding I need to replace a text field (teacher) in Table (attendance) with a lookup fileld. the lookup field will point to a newly created table (teachers) the original DB was never intended to do the job that it is doing, but
5
2888
by: CaliSchmuck | last post by:
I think this is probably simple, but I'm having a problem figuring it out. I have a form that is used to enter data. I want users to be able to enter a zip code in the form, and have the city and state come up automatically. I have two tables: Table 1 (14 fields): Customer Name, Address, City, State, Zip,
2
1633
by: HateSpam | last post by:
I have a paramter query that wants either of 2 date fields in a table to be before a certain date. Select * from tblExample where Date1 < or Date2 < When I open this query, it prompts me twice for dtCutoff. I've verified I'm using the same spelling and capitalization. Is there a way to make it only prompt once?
5
2005
by: Comcast Newsgroups | last post by:
I'm trying to put together a macro that queries my cell phone call expense DB the selects records as of a specific Date that are not marked "Archive", prints a report, then marks the records "Archive". I've worked out the Queries and the report and even got them into the macro but I can't figure out how to set up the Macro to prompt for ONE Date. Instead I get a prompt for the Select Query date and then again for the Update Query date. ...
2
4679
by: atreide_son | last post by:
hello all... yes i'm a newbie and i need help. i have an assignment due for class, but I don't know i'm stuck and can't get out from under myself. here's the focus of the program: Write a C program that allows the user to make some simple banking
17
3417
by: Liam.M | last post by:
Hey guys, Forgive me if my question my be alittle silly, but I would very much appreciate and assistance that could be given! My situation is as follows: I have created a Button, and set it's "On Click" Event proceedure to Loop through my Database and find any records that fall within a Certain Date...if a record is found...it then emails me that a record
6
6437
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the Autoexec Macro looks like the way to go. Could someone please assist? Thank you very much! Mike
4
1269
by: pms | last post by:
Need suggestions to improve this program. using System; namespace CalculateWage { class GetEmployeeDetails {
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.