Connecting Tech Pros Worldwide Forums | Help | Site Map

Dlookup from a Query

Newbie
 
Join Date: Sep 2008
Posts: 9
#1: Nov 20 '08
I am using Access 97 (No choice) and I trying to get the VBA to do this.

1. Open a query "X-Misses-1"
2. Pull the value from the field "total misses"
3. Use that value in a loop to run an append query that # of times.

Here is where I am, and I am stuck on

Expand|Select|Wrap|Line Numbers
  1.     Dim stDocName As String
  2.     Dim Temp As Integer
  3.     Dim Count As Integer
  4.  
  5.     stDocName = "X-Misses-1"
  6.     DoCmd.OpenQuery stDocName, acNormal, acEdit
  7.     Temp = DLookup("[total misses]")
  8.  
  9.     Count = 1
  10.     Do While Count <= Temp
  11.  
  12.  
  13.     stDocName = "X-Missesappend"
  14.     DoCmd.OpenQuery stDocName, acNormal, acEdit
  15.  
  16.     Count = Count + 1
  17.     Loop
  18.  
  19. Exit_Command54_Click:
  20.     Exit Sub
  21.  
  22. Err_Command54_Click:
  23.     MsgBox Err.Description
  24.     Resume Exit_Command54_Click
  25.  

Expert
 
Join Date: Jun 2007
Location: Derbyshire, UK
Posts: 347
#2: Nov 21 '08

re: Dlookup from a Query


Quote:

Originally Posted by jzalar

I am using Access 97 (No choice) and I trying to get the VBA to do this.

1. Open a query "X-Misses-1"
2. Pull the value from the field "total misses"
3. Use that value in a loop to run an append query that # of times.

Here is where I am, and I am stuck on

Expand|Select|Wrap|Line Numbers
  1.     Dim stDocName As String
  2.     Dim Temp As Integer
  3.     Dim Count As Integer
  4.  
  5.     stDocName = "X-Misses-1"
  6.     DoCmd.OpenQuery stDocName, acNormal, acEdit
  7.     Temp = DLookup("[total misses]")
  8.  
  9.     Count = 1
  10.     Do While Count <= Temp
  11.  
  12.  
  13.     stDocName = "X-Missesappend"
  14.     DoCmd.OpenQuery stDocName, acNormal, acEdit
  15.  
  16.     Count = Count + 1
  17.     Loop
  18.  
  19. Exit_Command54_Click:
  20.     Exit Sub
  21.  
  22. Err_Command54_Click:
  23.     MsgBox Err.Description
  24.     Resume Exit_Command54_Click
  25.  

Hi

Assuming 'X-Misses-1' is a stored query then have you tried this

Temp = DLookup("[total misses]","X-Misses-1") ??

Note: if the query 'X-Misses-1' has more that one record, then it will return the value of 'total misses' from the first record (i believe?), otherwise you need to use the optional third element 'WHERE' clause in DLookUp.


MTB
Reply