Solved

Access 2013

Posted on 2016-10-02
15
36 Views
Last Modified: 2016-10-23
In writing a macro expression for my access database I can't figure out wrong.
[Forms]![FrmTracker]![NumberOf Remaining Units]<100 Then MessageBox
0
Comment
Question by:Isaiah Noell
  • 5
  • 4
  • 3
  • +2
15 Comments
 
LVL 19
ID: 41825703
since you are referring to a subform, you must use .form after the subform controlname to go inside the form and reference what it contains

the subform itself is where the subform control is ... its position, size, etc

assuming your subform control Name IS the same as the SourceObject it contains:
[Forms]![FrmTracker].form![NumberOf Remaining Units]

Open in new window

0
 

Author Comment

by:Isaiah Noell
ID: 41825710
[Forms]![FrmTracker].[Form]![NumberOf Remaining Units]<100

I'm not really versed in access. I haven't really used it since Access 2003. I'm getting a error message Type mismatch.
0
 
LVL 19
ID: 41825713
try Forms!Formname.form.controlname

if names have spaces, substitute underscore --

however a type mismatch generally means a different data type was expected.  Is this a bound control? If so, what is the underlying data type?

If not, then Access assumes it is text and the value must be converted to a number to compare with a number
0
 

Author Comment

by:Isaiah Noell
ID: 41825745
Its a calculated field.
0
 
LVL 19
ID: 41825752
then in the equation to calculate, wrap with a conversion function such as cLng, cInt, cDbl to specify the data type.  You can also wrap the control reference.  If you wrap the reference, be sure to use NZ inside since a conversion function can't convert null.  For example, for Long Integer:
       cLng(NZ([Forms]![FrmTracker].form![NumberOf Remaining Units],0))

Open in new window

0
 

Author Comment

by:Isaiah Noell
ID: 41825762
First of all I want to say thank you for all your help.
 I tried  cLng(NZ([Forms]![FrmTracker].form![NumberOf Remaining Units],0)) and I got Error: subscript out of range.

I want a MessageBox to appear when NumberOf Remaining Units get below 100
It's doing the calculations correctly.
0
 
LVL 19
ID: 41825773
you're welcome

is the form open and on a record?

what is the equation for the calculated field?
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 75
ID: 41825779
Crystal ... what make you think the OP is using a subform ?
0
 
LVL 13

Expert Comment

by:John Tsioumpris
ID: 41825864
IF your subform has some code behind it you can use this :
Form_FrmTracker.Remaining 

Open in new window

If you don't have code behind just press the button of code...just to enter the VBE environment and leave...that would be enough
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 41825900
Write a piece of code as an EventProcedure in the AfterUpdate event of the textbox bound to [NumberOf Remaining Units]:
If Nz(Me![NumberOf Remaining Units].Value, 0) < 100 Then 
    MsgBox "Number of units must be larger than 100", vbInformation + vbOkOnly, "Remaining Units"
End If

Open in new window

/gustav
0
 

Author Comment

by:Isaiah Noell
ID: 41828619
This is what my event procedure looks like, what am I doing wrong?


Private Sub Command30_Click()

Call Auditchanges("PeerID1", "Delete")



DoCmd.GoToRecord , , acNext


End Sub

Private Sub Command48_Click()

End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord Then
    Call Auditchanges("PeerID1", "New")
Else
    Call Auditchanges("PeerID1", "Edit")
    End If
   
    End Sub

Private Sub NumberOf_Remaining_Units_AfterUpdate()

End Sub
If Nz(Me![NumberOf Remaining Units].Value, 0) < 100 Then
    MsgBox "Units are low contact System Administrator", vbInformation + vbOKOnly, "Remaining Units"
End If

Private Sub NumberOf_Remaining_Units_BeforeUpdate(Cancel As Integer)

End Sub
0
 
LVL 75
ID: 41828925
So what error are you getting now and where ?
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points (awarded by participants)
ID: 41829371
The code must be inside the function:
Private Sub NumberOf_Remaining_Units_AfterUpdate()

    If Nz(Me![NumberOf Remaining Units].Value, 0) < 100 Then
        MsgBox "Units are low, contact System Administrator", vbInformation + vbOKOnly, "Remaining Units"
    End If

End Sub

Open in new window

/gustav
0
 
LVL 19
ID: 41850190
Joe, "Crystal ... what make you think the OP is using a subform ?" -- gee, I don't know! Too much multi-tasking and not paying enough attention -- sorry!
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 41855858
Most likely the answer.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now