?
Solved

Option button keeps value across records

Posted on 2011-09-26
9
Medium Priority
?
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
9 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36599546
is the option "optAsset" bound to a field in the table?
0
 
LVL 58
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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
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
 

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 120

Expert Comment

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

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 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 58
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

765 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