Solved

Option button keeps value across records

Posted on 2011-09-26
9
233 Views
Last Modified: 2012-05-12
I created the code to click a option button on record, which turns a label visible, enables a cmd button and disables a text box. All of that works, but when I navigate to the next record the option button value keeps its value across the next record, and I don't want that, what I am missing??
Option Compare Database
Option Explicit



Private Sub Form_Current()
If Me.optAsset.Value = -1 Then
Me!lblAsset.Visible = True
Me!cmdUpdateID.Enabled = True
Me!AssetNo.Enabled = False
Else: Me!AssetNo.Enabled = True
Me!lblAsset.Visible = False
Me!cmdUpdateID.Enabled = False
End If
End Sub


Private Sub optAsset_Click()
If optAsset.Value = -1 Then
Me.lblAsset.Visible = True
Me.cmdUpdateID.Enabled = True
Me.AssetNo.Enabled = False
Me.Comment = (Date & " -- No ID was found on Equipment, please notify Department of use to fix this issue.")
Else
Me.lblAsset.Visible = False
Me.cmdUpdateID.Enabled = False
Me.AssetNo.Enabled = True
End If
End Sub

Private Sub cmdUpdateID_Click()
Dim i As String
i = InputBox("Enter Asset ID Number", "Asset ID")
Me.AssetNo.Enabled = True
Me.AssetNo = i
Me.optAsset.Value = 0
Me.lblAsset.Visible = False
Me.Comment = (Date & "  --  ID found and affixed to equipment")

End Sub

Open in new window

0
Comment
Question by:Engtech05
  • 3
  • 3
  • 3
9 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 36599546
is the option "optAsset" bound to a field in the table?
0
 
LVL 57
ID: 36599557

 You need to bind the control to a field in the record by setting it's controlsource or you need to assign the default value you want in the forms OnCurrent event, which fires when a record receives the focus.

Jim.
0
 

Author Comment

by:Engtech05
ID: 36599679
Ok the option button is not bound to anything, and I really dont need it to be. How do I get it to quit bringing everything over, the label the cmd button, I think I have got the option button, just not sure about the others.
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 36599716
<Ok the option button is not bound to anything, and I really dont need it to be>

then, you can not achieved what you are trying to do , using the form current event.
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.

 

Author Comment

by:Engtech05
ID: 36599735
Good to know in the future, so what do I need to do to fix this then. Can I bind it to the AssetNo field with it showing text "Unknown ID", if so how. I know how to bind it just no the text portion.
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 36599760
try adding a YESNo field to your table and bind the optAsset to that field.
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 36599779
OnCurrent event:

If NZ(Me.AssetNo,"") = "" then
  ' No Asset ID
  Me.lblAsset.Visible = True
  Me.cmdUpdateID.Enabled = True
  Me.AssetNo.Enabled = False
  Me.Comment = (Date & " -- No ID was found on Equipment, please notify Department of use to fix this issue.")
  Me.optAsset.Value = -1
Else
 ' Asset ID
  Me.lblAsset.Visible = False
  Me.cmdUpdateID.Enabled = False
  Me.AssetNo.Enabled = True
  Me.Comment = (Date & "  --  ID found and affixed to equipment")
  Me.optAsset.Value = 0
End If

Jim.
0
 

Author Closing Comment

by:Engtech05
ID: 36599819
Thanks Jim, really helpful. I appreciate the assistance.
0
 
LVL 57
ID: 36599913
Not a problem.

As an add-on, anytime your working with unbound controls on a form, I like to put all the logic for setting the "state" of things in a sub procedure in the form iteself.  ie.:

Procedure Sub SetFormControls()

If NZ(Me.AssetNo,"") = "" then
  ' No Asset ID
  Me.lblAsset.Visible = True
  Me.cmdUpdateID.Enabled = True
  Me.AssetNo.Enabled = False
  Me.Comment = (Date & " -- No ID was found on Equipment, please notify Department of use to fix this issue.")
  Me.optAsset.Value = -1
Else
 ' Asset ID
  Me.lblAsset.Visible = False
  Me.cmdUpdateID.Enabled = False
  Me.AssetNo.Enabled = True
  Me.Comment = (Date & "  --  ID found and affixed to equipment")
  Me.optAsset.Value = 0
End If

End Sub

  Then from the OnCurrent, you would do:

  Call SetFormControls()

 and the same from the AfterUpdate event of the control itself or any place else that you might be changing the state of the control or what it's tied to.

  This allows you to keep one copy of the code rather then having it in multiple places.

  That may not work in this case because on one hand your checking the field and setting the state of the controls, but in the update your checking the state of the control and setting the reset of the controls and the field.

Jim.
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DSum for Access 6 47
Unrecognized Database Format 8 93
Excess tables to Excel BackUp 3 29
Running Total in Access 4 17
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

895 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

15 Experts available now in Live!

Get 1:1 Help Now