Automatically added number in the form

F

Frank Situmorang

Helle,

In my membership input form, I have a field named:
Church Reg NO
in other field the membertype: there are 2 type "AM" and "SS".

Church Reg NO field table can only be assigned with number if the type is "AM"

What is the VBA for this in order to make Prompt or pop up the last number,
so that we can fill the next number, it will be better if it will
automatically, the last bigger number+1, but I do not know how to make it.

In your VBA please inform me if it is the name of the contorl surce field or
the name of the field table.

Thanks in advance

Frank
 
S

Steve Schapel

Frank,

If I understand you correctly, I think you could put code like this on
the After Update event of the Membertype control on your form...

If Me.membertype = "AM" Then
Me.Church_Reg_No = DMax("[Church Reg No]","YourTable") + 1
Else
Me.Church_Reg_No = Null
End If

(substitute the actual name of your table for "YourTable")
 
F

Frank Situmorang

Thanks Steve for your help, it works now. But we appreciate your help again.
Becauwe after I finished building this data base, I will give this to the
chruch secretarhy, after I train him. But it could be that membertype since
it is the combo box, the secretary could have an error, instead of AM type it
should have been SS type, waht would be the VBA to cancel the previous one.
The showed number should be cancel after we choose again the SS membertype.
and we have confirmed it, because I have put also confirmation in the
afterupdate, this is my VBA

Private Sub AngtType_AfterUpdate()
If Me.AngtType = "Anggota Jemaat" Then
Me.NoInd = Nz(DMax("[NoIn]", "bukuangkby")) + 1
Else
Me.NoInd = Null
End If
If Not IsNull(Me.[AngtType].OldValue) Then
If Me.[AngtType] <> Me.[AngtType].OldValue Then
If MsgBox("Anda telah merobah!!, apakah sengaja mau merobah?",
vbYesNo + vbDefaultButton2 + vbQuestion) = vbNo Then
' Undo the changes
Me.AngtType = Me.AngtType.OldValue
End If
End If
End If
End Sub
--
H. Frank Situmorang


Steve Schapel said:
Frank,

If I understand you correctly, I think you could put code like this on
the After Update event of the Membertype control on your form...

If Me.membertype = "AM" Then
Me.Church_Reg_No = DMax("[Church Reg No]","YourTable") + 1
Else
Me.Church_Reg_No = Null
End If

(substitute the actual name of your table for "YourTable")

--
Steve Schapel, Microsoft Access MVP

Frank said:
Helle,

In my membership input form, I have a field named:
Church Reg NO
in other field the membertype: there are 2 type "AM" and "SS".

Church Reg NO field table can only be assigned with number if the type is "AM"

What is the VBA for this in order to make Prompt or pop up the last number,
so that we can fill the next number, it will be better if it will
automatically, the last bigger number+1, but I do not know how to make it.

In your VBA please inform me if it is the name of the contorl surce field or
the name of the field table.

Thanks in advance

Frank
 
S

Steve Schapel

Frank,

As I understand it, there should be no need for this more complex code.
The code I gave you should already take care of that situation.
That's the meaning of the "Else Me.Church_Reg_No = Null" part of the
code. If the user will enter "SS" for type, then it should remove the
Number if there is one.
 
F

Frank Situmorang

Thanks very Steve, I will use your suggestion.

God bless
--
H. Frank Situmorang


Steve Schapel said:
Frank,

As I understand it, there should be no need for this more complex code.
The code I gave you should already take care of that situation.
That's the meaning of the "Else Me.Church_Reg_No = Null" part of the
code. If the user will enter "SS" for type, then it should remove the
Number if there is one.

--
Steve Schapel, Microsoft Access MVP

Frank said:
Thanks Steve for your help, it works now. But we appreciate your help again.
Becauwe after I finished building this data base, I will give this to the
chruch secretarhy, after I train him. But it could be that membertype since
it is the combo box, the secretary could have an error, instead of AM type it
should have been SS type, waht would be the VBA to cancel the previous one.
The showed number should be cancel after we choose again the SS membertype.
and we have confirmed it, because I have put also confirmation in the
afterupdate, this is my VBA

Private Sub AngtType_AfterUpdate()
If Me.AngtType = "Anggota Jemaat" Then
Me.NoInd = Nz(DMax("[NoIn]", "bukuangkby")) + 1
Else
Me.NoInd = Null
End If
If Not IsNull(Me.[AngtType].OldValue) Then
If Me.[AngtType] <> Me.[AngtType].OldValue Then
If MsgBox("Anda telah merobah!!, apakah sengaja mau merobah?",
vbYesNo + vbDefaultButton2 + vbQuestion) = vbNo Then
' Undo the changes
Me.AngtType = Me.AngtType.OldValue
End If
End If
End If
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

Top