Access VBA Checkbox error 2447 - ms-access

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.

Related

Three Options - Enabling/Disabling based on input and record value

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.

Runtime Error 438 Hiding Page

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

MS Access subform not displaying records and not navigating

I have a one-to-one relationship between an SLD table and an ORDER table. The SLD table is the main form, ORDER table is the subform. The main form's table has more records than the subform table. Master and child links are set. I have decompiled and have done compact and repair. I suspect my application is malfunctioning. In that case it is not the first time (I have fixed it before). Nothing seems to be working this time. I have also imported into a new database.
On form-load both forms and fields are working fine. I continue to the next records using a ['NEXT'] button and reach the end of the sub-forms records therefore having blanks fields. I try to navigate to the previous records (also using a button) but the subform does not move/navigate. Nothing happens to the subform.
It seems like it has gotten worse because first it was navigating but it was not obeying code saying when text box is filled disable checkbox and vise versa.
From the sounds of it the issue is in your Next button rather than it being a subform issue. As you stated in the comments the default navigation allows the form to work as expected.
Is this logic out in your Previous button OnClick Event? Also to be safe i would add in the OR statement in the below code to be extra sure that its catching nulls or blanks
If (IsNull(Forms!Order!OrderSubform.Form!txtDate_Of_Order.Value‌​)) OR Forms!Order!OrderSubform.Form!txtDate_Of_Order.Value‌​ <> "" Then
Forms!Order!OrderSubform.Form!txtDate_Of_Order.Enabled = False
Forms!Order!OrderSubform.Form!chkbxOrder_Cancelled.Enabled = True
Forms!Order!OrderSubform.Form!chkbxOrder_Cancelled.Value = True
Else
Forms!Order!OrderSubform.Form!txtDate_Of_Order.Enabled = True
Forms!Order!OrderSubform.Form!chkbxOrder_Cancelled.Enabled = False
Forms!Order!OrderSubform.Form!chkbxOrder_Cancelled.Value = False
End If
I found out that the If statement belonged in Form_Current event. I am not experiencing the problem anymore after this code:
Private Sub Form_Current()
If (IsNull(Forms!Order!OrderSubform.Form!txtOrder_Number.Value) Or _
Forms!Order!OrderSubform.Form!txtOrder_Number.Value = "") Then
Forms!Order!OrderSubform.Form!txtDate_Of_Order.Enabled = True
Forms!Order!OrderSubform.Form!chkbxOrder_Cancelled.Enabled = True
ElseIf (IsNull(Forms!Order!OrderSubform.Form!txtDate_Of_Order.Value) Or _
Forms!Order!OrderSubform.Form!txtDate_Of_Order.Value = "") Then
Forms!Order!OrderSubform.Form!txtDate_Of_Order.Enabled = False
Forms!Order!OrderSubform.Form!chkbxOrder_Cancelled.Enabled = True
Forms!Order!OrderSubform.Form!chkbxOrder_Cancelled.Value = True
Else
Forms!Order!OrderSubform.Form!txtDate_Of_Order.Enabled = True
Forms!Order!OrderSubform.Form!chkbxOrder_Cancelled.Enabled = False
Forms!Order!OrderSubform.Form!chkbxOrder_Cancelled.Value = False
End If
End Sub

Setting a form's Record Source on Load event

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.

VBA - "Compile Error: Method or data member not found"

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.