473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Form ONCurrent only Else is effected

Hello,

I dont know why only else part of if statement is effected when using
below

Private Sub Form_Current()
If Me.NewRecord Then
Me!nrpoz = DMax("[Nr_poz]", "[ZESTAWIENIE_MATERIALOW]",
"[Id_projektu]= '" & Me.Parent.Nr_artykulu & "'") + 1
Else
Me!nrpoz = Me!Nr_poz
End If
End Sub
Isn't it new record when entering first data to a row?
Jul 29 '08 #1
1 1359
Suggestions:

1. Never use Form_Current to assign a value to a bound control. There is no
point in dirtying the record just because you visited it. You are creating
many unnecessary writes, and increasing the chance of errors (e.g.
concurrency problems.)

2. Do you really need an event? If you set up your subform so the
LinkMasterFields/LinkChildFields work, you don't need any code at all, and
the child fields inherit the value of the master fields.

3. If you can't do that, use Form_BeforeInsert. This event fires when the
user starts entering something (so only when needed.)

The example below assumes that:
- Nrprojektu is a Text field (not a Number field.)
- Nr_poz is a Number field (not a Text field.)
- The subform has fields or controls named Nr_artykulu and nrpoz.
- You don't have to worry about multiple users entering data at the same
time, and getting the same number assigned.

Private Sub Form_BeforeInsert(Cancel As Integer)
Dim strWhere as String
With Me.Parent
If .NewRecord Then
Cancel = True
MsgBox "Enter a record in the main form first."
Else
strWhere = "[Id_projektu]= """ & !Nr_artykulu & """"
Me.nrpoz = Nz(DMax("[Nr_poz]", "[ZESTAWIENIE_MATERIALOW]",
strWhere), 0) + 1
End If
End With
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Maciej Franciszkowski" <ma******@poczta.onet.plwrote in message
news:57**********************************@z72g2000 hsb.googlegroups.com...
Hello,

I dont know why only else part of if statement is effected when using
below

Private Sub Form_Current()
If Me.NewRecord Then
Me!nrpoz = DMax("[Nr_poz]", "[ZESTAWIENIE_MATERIALOW]",
"[Id_projektu]= '" & Me.Parent.Nr_artykulu & "'") + 1
Else
Me!nrpoz = Me!Nr_poz
End If
End Sub
Isn't it new record when entering first data to a row?
Jul 29 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Terry | last post by:
Hello, I am designing a form and need to know how to get a Check Box(PASS)to automatically update when the data in a Text Box (MARK), in the same form, is >=24. Using the Event dialogue box for...
3
by: William Wisnieski | last post by:
Hello Everyone, Access 2000, I have a main unbound form with a bound datasheet subform . The subform is bound to a query that returns records based on criteria in the main form. The user...
2
by: Brainwave Surfer | last post by:
Am trying to grey out a field in a form depending on if there's a date in it or not, using access 2000, and i've tried vbscript and macros... I've read and tried and reread for a week... I'll be...
9
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a main form with a continuous subform. On the main form I have a text field called . It gets populated based on what the user selects in a field on the...
5
by: Michelle | last post by:
Hi all Is it possible to have 2 subforms on a form but have the second subform linked to the 1st subform. I will explain the situation. My form contains details of teams and the shift the...
3
by: MLH | last post by:
I have a form, bound to a query. Its RecordSource property is a query named frmEnterLienAmounts. The form has a few bound controls and some unbound controls. The unbound controls are calculated...
16
by: usenet | last post by:
I want to be able to use the record numbers of a sub-form, are they available anyhow in VB (Access 2003)? I want to use the sub-form record number as *part* of the primary key for the table...
1
by: mssbass | last post by:
In order to disable the previous and next buttons on my form, I followed the attached code. The buttons seem to work fine except for one thing. When the form first opens, the next button is...
3
by: Dave S | last post by:
Hello Everyone, I have a form in a multi-user database that flashes when the form is opened. This is a failr involved form that contains header information along with a continous subform. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...

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.