form issue...please help

C

cho

Hi all,
I just made a form and I have some question about it,
1.I want to make a text box which displaye a field from the last
record entered.( just for refference when entering new record )

2.How to move cursor automatically to the field where the error come from
when we made some mistake (ex : wrong entered data type or leave blank field
while the field may not blank or enter replica to a primary field where not
allowed )
and try to saving.
 
R

Ruel via AccessMonster.com

Step 1. Create a "Public Variable" in code behind the form. See below:

Public varLastEntry As Variant


Step 2. Create an Unbound field on your form name "LastEntry".


Step 3. On the field that you want the information from Create an
"AfterUpdate Event Procedure"
to transfer the data from the field to the public variable.
On my form I did this to a field called "LastName". See below:

Private Sub LastName_AfterUpdate()

varLastEntry = Me.LastName
Me.LastEntry = varLastEntry

End Sub


Step 4. Add a new record and enter information into the field with the
AfterUpdate Event Procedure.


Step 5. Add another new record and the unbound field named "LastEntry" will
display the last entry.


Ruel
 
C

cho

Hi
It doesn't work Ruel
First I declare

Public varLastEntry As Variant

And then build code like this

Private Sub Registrasi_No_AfterUpdate()

varLastEntry = Me.Registrasi No
Me.LastEntry = varLastEntry

End Sub

But VB send me the error message

Method or data not found.

Why is there something wrong


Ruel via AccessMonster.com said:
Step 1. Create a "Public Variable" in code behind the form. See below:

Public varLastEntry As Variant


Step 2. Create an Unbound field on your form name "LastEntry".


Step 3. On the field that you want the information from Create an
"AfterUpdate Event Procedure"
to transfer the data from the field to the public variable.
 
M

missinglinq via AccessMonster.com

varLastEntry = Me.Registrasi No

should be, by your own code

varLastEntry = Me.Registrasi_No


Hi
It doesn't work Ruel
First I declare

Public varLastEntry As Variant

And then build code like this

Private Sub Registrasi_No_AfterUpdate()

varLastEntry = Me.Registrasi No
Me.LastEntry = varLastEntry

End Sub

But VB send me the error message

Method or data not found.

Why is there something wrong
Step 1. Create a "Public Variable" in code behind the form. See below:
[quoted text clipped - 36 lines]
Message posted via AccessMonster.com

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
R

Ruel via AccessMonster.com

You were missing an underscore "_" between Me.Registrasi and No.


varLastEntry = Me.Registrasi_No



Ruel

varLastEntry = Me.Registrasi No

should be, by your own code

varLastEntry = Me.Registrasi_No
Hi
It doesn't work Ruel
[quoted text clipped - 22 lines]
 
G

Guest

OK Ruel,
What about my first question
It's about Error Handling
I need help to build code for Error Go To Label,please

Ruel via AccessMonster.com said:
You were missing an underscore "_" between Me.Registrasi and No.


varLastEntry = Me.Registrasi_No



Ruel

varLastEntry = Me.Registrasi No

should be, by your own code

varLastEntry = Me.Registrasi_No
Hi
It doesn't work Ruel
[quoted text clipped - 22 lines]
Message posted via AccessMonster.com
 
R

Ruel Cespedes via AccessMonster.com

Error Handling is all conditional. It will depend on the Field type. You
can create an AfterUpdate Procedure for each field needing to be validated.
Here is an example:

Let's say you have a field on your form called Date. Created an AfterUpdate
Procedure that validates the entry. I want the code to check if the date
entered is Less Than January 1, 2007. This is what it will look like:

Private Sub Date_AfterUpdate()

If Me.Date < #01/01/2007# Then
MsgBox "You have Entered a Date less than January 1, 2007!"
'Popup Error Message.
Me.Date.SetFocus
'Set Focus back to field.
Else
SendKeys "{TAB}"
'If not Tabs to next field.
End If

End Sub


Ruel
 
C

cho

What if I have a field which the data type is Number
and on the table Required is set to Yes.What is the code
 
R

Ruel Cespedes via AccessMonster.com

Private Sub FieldName_AfterUpdate()

'Check if Number Field is Empty
If IsNull(Me.FieldName) Then

'Popup Error Message.
MsgBox "This is a Required Field."

'Set Focus back to field.
Me.FieldName.SetFocus

Else

'If not Tab to next field.
SendKeys "{TAB}"

End If

End Sub

Ruel
 
C

cho

It's working Ruel Thank's
But,by the way
About the last entry,it works manually
can we set it to work automatically
 
R

Ruel Cespedes via AccessMonster.com

You will have to do an AfterUpdate Procedure for each field and Insert the
SetFocus back to the field like this:

'Set Focus back to field.
Me.FieldName.SetFocus


Replace FieldName with the real field name in question.

You can also do a cool visual change to the field and change the color to red
like this:

'Set BackColor to Red
Me.FieldName.BackColor = 255 '255 Color Code for Red


Ruel
 
R

Ruel Cespedes via AccessMonster.com

Private Sub FieldName_AfterUpdate()
On Error GoTo Error_Err

'Check if Number Field is Empty
If IsNull(Me.FieldName) Then

'Popup Error Message.
MsgBox "This is a Required Field."

'Set Focus back to field.
Me.FieldName.SetFocus

Else

'If not Tab to next field.
SendKeys "{TAB}"

End If


Error_Exit:
Exit Sub

Error_Err:
MsgBox Error$
'Set Focus back to field.
Me.FieldName.SetFocus
Resume Error_Exit

End Sub
 
C

cho

I finish with the error go to label Ruel,
I confuse about the last entry field.
I want to display automatically a data
from a field from the last record and not change
until we save the new record
 
R

Ruel Cespedes via AccessMonster.com

Please list all your Required Fields and their Data Types

Example:

Field Name Type
=================
Name Text
Date Date/Time
Notes Meno
Amount Number
Car Pool Yes/No
URL Hyperlink
Photo OLE Object
 
C

cho

Ruel I made a change the fields aren't required anymore.

Field Name Data Type
===================
1.Registration_No Number ( PK )
2.Date Date/Time
3.Model Text (combo box and limit to list )
 

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