I have been developing an Access form to operate as a frontend for a SQL database. I have been working with a developer, and they added the following VBA code to our main form:
Private Sub Form_Current()
If Me.NewRecord = True Then
Me.Client_Name.Enabled = True
Me.SSN.Enabled = True
Me.DOB.Enabled = True
Me.Prob_Fee.Enabled = True
Me.Settle_Atty_Amt.Enabled = True
Me.Settle_Date.Enabled = True
Me.Final_Date.Enabled = True
Else
Me.Client_Name.Locked = True
Me.SSN.Locked = True
Me.DOB.Locked = True
Me.Prob_Fee.Locked = True
Me.Settle_Atty_Amt.Locked = True
Me.Settle_Date.Locked = True
Me.Final_Date.Locked = True
End If
End Sub
When I try to add a new variable to this statement Me.Case_ID.Locked = True, the following error is returned:
Compile Error: Method or data member not found
I'm not sure where to go from here.
Make sure that you are referring to the name of the control that you just added. It may not be the same as the field / column contained. On the 'Other' tab of the property sheet, you will find Name, that is the property you need. It is often different from the name of the control contained.
Related
I have a form where (among other things) there are three options which are intended to be exclusive.
optDealerPay
optCustomerPay
optNoTradeIn
I want only one to be selected at a time, but when I originally designed this, I made these into three separate table columns instead of one and using an option group. Mostly because of the output I'm wanting on a report I'm working on, too. Anyway, when one is selected, the other two go Enabled = False. The issue I'm having is when the form loads (actually using Form_Current() to ensure the record is loaded prior to "checking"), the form will disable one of the two options that are unselected, but not the other one. Here is a picture:
And here is the code I'm using:
Private Sub Form_Current()
If Me.optDealerPay Then
Me.optCustomerPay.Enabled = False
Me.optNoTradeIn.Enabled = False
Else
Me.optCustomerPay.Enabled = True
Me.optNoTradeIn.Enabled = True
End If
If Me.optCustomerPay Then
Me.optDealerPay.Enabled = False
Me.optNoTradeIn.Enabled = False
Else
Me.optDealerPay.Enabled = True
Me.optNoTradeIn.Enabled = True
End If
If Me.optNoTradeIn Then
Me.optDealerPay.Enabled = False
Me.optCustomerPay.Enabled = False
Else
Me.optDealerPay.Enabled = True
Me.optCustomerPay.Enabled = True
End If
End Sub
What's a better method to accomplish this outside of redesigning the table structure, which I'm really trying to avoid if possible. Similar code is used with the AfterUpdate() procedure on each of the three options.
Your code will execute every if statement one by one - that is some kind of mess. Make all radiobuttons enabled in design mode and try this code:
Private Sub Form_Current()
If Me.optDealerPay Then
Me.optCustomerPay.Enabled = False
Me.optNoTradeIn.Enabled = False
ElseIf Me.optCustomerPay Then
Me.optDealerPay.Enabled = False
Me.optNoTradeIn.Enabled = False
ElseIf Me.optNoTradeIn Then
Me.optDealerPay.Enabled = False
Me.optCustomerPay.Enabled = False
Else
' Maybe you should do something if none of the options is true
End If
End Sub
Your current code could essentially be reduced to:
Private Sub Form_Current()
optDealerPay.Enabled = Nz(optDealerPay, 0)
optCustomerPay.Enabled = Nz(optCustomerPay, 0)
optNoTradeIn.Enabled = Nz(optNoTradeIn, 0)
End Sub
That is, if a radio button is null or unchecked, then it is disabled; else it is enabled.
However, although this is the behaviour that you have requested, I'm not sure that this is desirable, as once the user has select an option they cannot change it.
I have a report I'm trying to create. One of the options in the form is Symbol with a dropbox for users to select X, /, or -
If the X is visible, I want the respective image (large red version of symbol) to be visible.
I have built event on Report Load:
Private Sub Report_Load()
Select Case Me.Symbol
Case "X"
Me.ImageX.Visible = True
Me.ImageDash.Visible = False
Me.ImageDiagonal.Visible = False
Case "-"
Me.ImageX.Visible = False
Me.ImageDash.Visible = True
Me.ImageDiagonal.Visible = False
Case "/"
Me.ImageX.Visible = False
Me.ImageDash.Visible = False
Me.ImageDiagonal.Visible = True
Case Else
Me.ImageX.Visible = True
Me.ImageDash.Visible = True
Me.ImageDiagonal.Visible = True
End Select
End Sub
Any ideas on what I'm missing?
As suggested by June, use the On Format event for the relevant section in which the objects reside, as the various object references do not hold values until after the On Load event of the report. For more information regarding the order of events, you may wish to refer to this documentation.
I might also suggest condensing your code to the following:
Private Sub Detail_Format()
Me.ImageX.Visible = Me.Symbol = "X"
Me.ImageDash.Visible = Me.Symbol = "-"
Me.ImageDiagonal.Visible = Me.Symbol = "/"
End Sub
I receive a
run-time error 438
when changing visibility of a page in Access VBA. The code below is called "AfterUpdate" for a listbox. I believe my syntax is correct after much review. I've tested the conditional statements with MsgBox's successfully.
Any ideas?
Public Sub RefreshControlTabs()
If [Forms]![frmPrintPostage_Email_DB]![subfrm_CampaignData]![Channel].Value = "Mail" Then
[Forms]![frmPrintPostage_Email_DB]![subfrm_CampaignData].[tabChannelControl].Pages(0).Visible = True
[Forms]![frmPrintPostage_Email_DB]![subfrm_CampaignData].[tabChannelControl].Pages(1).Visible = False
ElseIf [Forms]![frmPrintPostage_Email_DB]![subfrm_CampaignData]![Channel].Value.Value = "Email" Then
[Forms]![frmPrintPostage_Email_DB]![subfrm_CampaignData].[tabChannelControl].Pages(1).Visible = True
[Forms]![frmPrintPostage_Email_DB]![subfrm_CampaignData].[tabChannelControl].Pages(0).Visible = False
Else
'do nothing
MsgBox "Valid Email/Mail channel not found for this job."
[Forms]![frmPrintPostage_Email_DB]![subfrm_CampaignData].[tabChannelControl].Pages(0).Visible = True
[Forms]![frmPrintPostage_Email_DB]![subfrm_CampaignData].[tabChannelControl].Pages(1).Visible = False
End If
End Sub
Perhaps your line:
ElseIf [Forms]! ... [Channel].Value.Value = "Email" Then
Should be:
ElseIf [Forms]! ... [Channel].Value = "Email" Then
I was hoping to use one form that has 3 layouts, but change the data source as the form loads. Here is the code that is called during OnLoad
Private Sub ShowInputLog(iLogType As Integer)
'Determines the Log Type Layout
'For data entry
Select Case iLogType
Case 1 '"MIPR"
Me.Caption = "MIPR"
Me.RecordSource = "tbl_MIPR"
Me.TabCodes.Pages(0).Visible = True
Me.TabCodes.Pages(0).Enabled = True
Me.cmbPR_NUM.SetFocus
Me.TabCodes.Pages(1).Visible = False
Me.TabCodes.Pages(2).Visible = False
Case 2 '"SPSPR"
Me.RecordSource = "tbl_SPSPR"
Me.Caption = "SPSPR"
Me.TabCodes.Pages(0).Visible = False
Me.TabCodes.Pages(1).Visible = True
Me.cmbPR_Contr.SetFocus
Me.TabCodes.Pages(2).Visible = False
Case 3 '"WBS"
Me.RecordSource = "tbl_WBS"
Me.Caption = "WBS"
Me.TabCodes.Pages(0).Visible = False
Me.TabCodes.Pages(1).Visible = False
Me.TabCodes.Pages(2).Visible = True
Me.cmbWBS_Num.SetFocus
End Select
End Sub
Will this work? I was hoping to see the recordsource property with my table defined, but it remains blank.
Yes, this should work, but all tables should have displayed columns with the same names. If you have different names, create few subforms and change subform's SourceObject property on main form depending on iLogType
Yes, this should work, but all tables should have displayed columns with the same names. If you have different names, create a query on each table, having identical field names, expected by the form.
Such code runs on one of my Apps for 9 different queries.
Ok, I'm getting the error 2447 when trying to create a new record in my database. Here is the code that is have.
'This checks the record each time a record is changed to see if it needs to display the text boxes
Private Sub Form_Current()
If Me.SigCheck = 1 then <--This is where I'm getting the error.
SigSerialtxt.Visible = True
SigSeriallbl.Visible = True
SigAssettxt.Visible = True
SigAssetlbl.Visible = True
Else
SigSerialtxt.Visible = False
SigSeriallbl.Visible = False
SigAssettxt.Visible = False
SigAssetlbl.Visible = False
End if
End Sub
I've tried to change the variable to True, as well as -1, but neither of the work. I'm lost as to what to use.
fixed the issue, I set the default to 0, now there is no error and it works properly.