Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem printing multiple letters in batch.

Status
Not open for further replies.

needadvice

Programmer
Apr 7, 2002
145
US
I have a DataEntry form with a temp table. Letters print from the temp table in batch. This works fine if the letters are all the same, but if I have code on the print button to select various letters based on a DLookup field in the table, it looks for the first variable then prints all the letters in the table based on that variable. It appears to read the code only once instead of for each report. Is there another way to write this code. Should I put it somewhere other than on the print button.
I'd appreciate any suggestions.

CODE Example:
'Selects the appropriate letter for printing.
Dim VarX As String

VarX = DLookup("[LETTER]", "[COD/TEMP]")

If VarX = ("Formerly Indebted") Then
DoCmd.OpenReport "Formerly/Indebted/letter", acViewNormal

ElseIf VarX = ("Warrant") Then
DoCmd.OpenReport "Warrant Letter", acViewNormal

ElseIf VarX = ("Balance") Then
DoCmd.OpenReport "Balance Letter", acViewNormal

'Ect,Ect...


End If

This will print three "Formerly indebted" letters instead of one of each letter type.
 
Hi,

I don't think that you fully understand VB code, also, I don't think that you fully understand how the DLOOKUP function works (don't worry - I don't either).

Your code:

VarX = DLookup("[LETTER]", "[COD/TEMP]") etc. will place ONE single value in Varx.

When you check for the content of Varx:

"If VarX = ("Formerly Indebted") Then ....
ElseIf VarX = ("Warrant") Then...
ElseIf VarX = ("Balance") Then..."

then VarX must be equal to "Formerly Indebted" for you to get the behaviour that you are getting.

To prove this, place "msgbox VarX" straight after your assignment like so:

VarX = DLookup("[LETTER]", "[COD/TEMP]")
msgbox VarX

To prove what the DLOOKUP function is returning, then do this:

VarX = DLookup("[LETTER]", "[COD/TEMP]")
msgbox DLookup("[LETTER]", "[COD/TEMP]")

It MUST also be returning "Formerly Indebted" for you to get the behaviour that you are getting.
---------------------------------------------------------

After looking at the DLOOKUP function, it requires 3 parameters: DLookup(expr, domain[, criteria]).
It allows you to get additional information from tables that are not retrieved by the current form.
You seem to be just supplying the expr part numerous times.

Post some more info about your table(s) in particular and exactly what you want to do.

Regards,

Darrylle











"Never argue with an idiot, he'll bring you down to his level - then beat you with experience."
 
I need the DLookup to process for each record in the Temp table. Someone told me a Loop statement would accomplish this. I'm learning VB as I go and have never written a loop statement. Would it be 'Loop Until EOF'? How do I incorporate a loop statement in my code as posted above?
Am I going in the right direction with this?
Any help appreciated.
 
Hi Needadvice,

Sorry mate - I could be here all year telling you (and loads of people) how to do stuff like this at your level.

I really think that you should get more of a foundation in VB and Access via a short college course perhaps.
You'll find it tough I think, otherwise.

Regardless.... look at the DLOOKUP function from Access help, and experiment with small tables until you get the results that you want - you will then understand DLOOKUP.

As for 'FOR..NEXT' loops etc, you had the syntax right (Access would have given you an error otherwise), but the values that you were checking for would never be an option because DLOOKUP as you used it was wrong.

Ask for help on DLOOKUP in this forum when you've experimented with it and got stuck - don't ask for a complete solution, you're more likely to get a good response.

Regards (and keep trying),

Darrylles




"Never argue with an idiot, he'll bring you down to his level - then beat you with experience."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top