Help with code.

L

Lasse T

Hello !!
This is probably a simple one for all you gurus out there.
This code loops thru a continous form and fill the field "fakturanummer"
with "1" added to it for each record starting with the highest value from
the order table +1. Then the user pushes a print button to print invoices.
When the invoice are printed it will never show up in this form again. So
far so good. The trouble starts if the user for some reason closes the form
without pushing the print button. Next time the form are opened the same
orders will come up again and they will get new invoice numbers.
If I could get the loop to only update the field if it is null or zero it
would solve my problem.

Many thanks in advance.

Lasse T
-----------------

Private Sub Form_Load()
With Me.RecordsetClone
If .RecordCount > 0 Then
.MoveFirst
Do While Not .EOF
.Edit
.Fields("Fakturanummer") = DMax("fakturanummer", "order") + 1
.Update
.MoveNext
Loop
End If
End With
With Me.RecordsetClone
If .RecordCount > 0 Then
.MoveFirst
Do While Not .EOF
.Edit
![Fakturadatum] = Date
.Update
.MoveNext
Loop
End If
End With

End Sub
 
P

prabha

Hi,

Have you tried:

.Edit
IF IsNull(.Fields("Fakturanummer") OR .Fields("Fakturanummer") = 0
THEN
.Fields("Fakturanummer") = DMax("fakturanummer", "order") + 1
END IF
.Update

I hope this helps! If you have additional questions on this topic, please
respond back to this posting.


Regards,

Eric Butts
Microsoft Access Support

"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
<http://www.microsoft.com/security/security_bulletins/ms03-026.asp> and/or
to visit Windows Update at <http://windowsupdate.microsoft.com/> to install
the patch. Running the SCAN program from the Windows Update site will help
to insure you are current with all security patches, not just MS03-026."



--------------------
| From: "Lasse T" <[email protected]>
| Newsgroups: microsoft.public.access.formscoding
| Subject: Help with code.
| Date: Sun, 8 Feb 2004 15:45:38 +0100
| Lines: 44
| Message-ID: <[email protected]>
| NNTP-Posting-Host: 213.150.141.235
| X-Trace: news.uni-berlin.de 1076251409 36583696 I 213.150.141.235
([219006])
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
.phx.gbl!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!f
u-berlin.de!uni-berlin.de!213.150.141.235!not-for-mail
| Xref: cpmsftngxa07.phx.gbl microsoft.public.access.formscoding:219669
| X-Tomcat-NG: microsoft.public.access.formscoding
|
| Hello !!
| This is probably a simple one for all you gurus out there.
| This code loops thru a continous form and fill the field "fakturanummer"
| with "1" added to it for each record starting with the highest value from
| the order table +1. Then the user pushes a print button to print invoices.
| When the invoice are printed it will never show up in this form again. So
| far so good. The trouble starts if the user for some reason closes the
form
| without pushing the print button. Next time the form are opened the same
| orders will come up again and they will get new invoice numbers.
| If I could get the loop to only update the field if it is null or zero it
| would solve my problem.
|
| Many thanks in advance.
|
| Lasse T
| -----------------
|
| Private Sub Form_Load()
| With Me.RecordsetClone
| If .RecordCount > 0 Then
| .MoveFirst
| Do While Not .EOF
| .Edit
| .Fields("Fakturanummer") = DMax("fakturanummer", "order") + 1
| .Update
| .MoveNext
| Loop
| End If
| End With
| With Me.RecordsetClone
| If .RecordCount > 0 Then
| .MoveFirst
| Do While Not .EOF
| .Edit
| ![Fakturadatum] = Date
| .Update
| .MoveNext
| Loop
| End If
| End With
|
| End Sub
|
|
|
 
L

Lasse T

Yes!! It works fine. Thank you wery much.

Lasse T
--------------

"prabha" said:
Hi,

Have you tried:

.Edit
IF IsNull(.Fields("Fakturanummer") OR .Fields("Fakturanummer") = 0
THEN
.Fields("Fakturanummer") = DMax("fakturanummer", "order") + 1
END IF
.Update

I hope this helps! If you have additional questions on this topic, please
respond back to this posting.


Regards,

Eric Butts
Microsoft Access Support

"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
<http://www.microsoft.com/security/security_bulletins/ms03-026.asp> and/or
to visit Windows Update at <http://windowsupdate.microsoft.com/> to install
the patch. Running the SCAN program from the Windows Update site will help
to insure you are current with all security patches, not just MS03-026."



--------------------
| From: "Lasse T" <[email protected]>
| Newsgroups: microsoft.public.access.formscoding
| Subject: Help with code.
| Date: Sun, 8 Feb 2004 15:45:38 +0100
| Lines: 44
| Message-ID: <[email protected]>
| NNTP-Posting-Host: 213.150.141.235
| X-Trace: news.uni-berlin.de 1076251409 36583696 I 213.150.141.235
([219006])
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08phx.gbl!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!f
u-berlin.de!uni-berlin.de!213.150.141.235!not-for-mail
| Xref: cpmsftngxa07.phx.gbl microsoft.public.access.formscoding:219669
| X-Tomcat-NG: microsoft.public.access.formscoding
|
| Hello !!
| This is probably a simple one for all you gurus out there.
| This code loops thru a continous form and fill the field "fakturanummer"
| with "1" added to it for each record starting with the highest value from
| the order table +1. Then the user pushes a print button to print invoices.
| When the invoice are printed it will never show up in this form again. So
| far so good. The trouble starts if the user for some reason closes the
form
| without pushing the print button. Next time the form are opened the same
| orders will come up again and they will get new invoice numbers.
| If I could get the loop to only update the field if it is null or zero it
| would solve my problem.
|
| Many thanks in advance.
|
| Lasse T
| -----------------
|
| Private Sub Form_Load()
| With Me.RecordsetClone
| If .RecordCount > 0 Then
| .MoveFirst
| Do While Not .EOF
| .Edit
| .Fields("Fakturanummer") = DMax("fakturanummer", "order") + 1
| .Update
| .MoveNext
| Loop
| End If
| End With
| With Me.RecordsetClone
| If .RecordCount > 0 Then
| .MoveFirst
| Do While Not .EOF
| .Edit
| ![Fakturadatum] = Date
| .Update
| .MoveNext
| Loop
| End If
| End With
|
| End Sub
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help with loop 2
Do/Loop Dilemma 6
Running Error Checks on SubForm 1
Error with form.requery (no current record) 3
Please help with a Do/Loop 3
Nested IF 7
Loop inside a loop 6
Code Help 10

Top