Runtime Error 438 Hiding Page - ms-access

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

Related

Making a form read-only for a certain user type

I have created a login form with a combo box for the user type (Admin, User) and a text box for the password. The code for the form is as follows.
Private Sub txtPassword_AfterUpdate()
If IsNull(Me.cboUser) Then
MsgBox "You need to select a user!", vbCritical
Me.cboUser.SetFocus
Else
If Me.txtPassword = Me.cboUser.Column(2) Then
If Me.cboUser.Column(3) = True Then
MsgBox "Password does not match, please re-enter!", vboOkOnly
Me.txtPassword = Null
Me.txtPassword.SetFocus
End If
DoCmd.OpenForm "FE1"
Me.Visible = False
Else
MsgBox "Password does not match, please re-enter!", vboOkOnly
Me.txtPassword = Null
Me.txtPassword.SetFocus
End If
End If
End Sub
Private Sub cboUser_AfterUpdate()
Forms!frmLogin!cboUser.Column (2)
End Sub
If the log in is as a User, when they get to the FE1 form, I want them just to be able to read the form, and not make any changes. The code I've been trying to use for this is as follows:
Private Sub Form_Open()
If Forms!frmLogin!cboUser.Column(2) = 2 Then
Me.AllowEdits = False
Me.AllowAdditions = False
Me.AllowDeletes = False
Else
Me.AllowEdits = True
Me.AllowAdditions = True
Me.AllowDeletes = True
End If
End Sub
But I keep getting the error:
The expression On Open you entered as the event property setting
produced the following error: Procedure declaration does not
match description of event or procedure having the same name.
*The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure].
*There may have been an error evaluating the function, event, or macro.
It's possible I've just been looking at this for too long, but I can't figure out where I've gone wrong!?
Your Form_Open procedure has the wrong signature, missing the Cancel parameter.
It must be:
Private Sub Form_Open(Cancel As Integer)
Don't write event procedures by hand, let Access create them.
Edit
I suggest you completely remove the Form_Open sub. Then let Access create it from the property sheet.
And you can simplify your code by using a variable like this:
Private Sub Form_Open(Cancel As Integer)
Dim AllowWriting As Boolean
AllowWriting = Not (Forms!frmLogin!cboUser.Column(2) = 2)
Me.AllowEdits = AllowWriting
Me.AllowAdditions = AllowWriting
Me.AllowDeletes = AllowWriting
End Sub
or even shorter with the RecordsetType Property:
Private Sub Form_Open(Cancel As Integer)
If Forms!frmLogin!cboUser.Column(2) = 2 Then
Me.RecordsetType = 2 ' Snapshot = read-only
Else
Me.RecordsetType = 0 ' Dynaset = read-write
End If
End Sub

"Add Record" gives "Can't go to specified record" after first use Access

I have a command button in a form that allows users to add a new record. The command only works the first time you click it after the form is opened. I can navigate through the records without any errors and the first time you add a record after the form is opened will not give errors. Once you try to add a second record, the "Can't go to the specified record" error message is displayed.
I can make edits in the query without a problem and I can edit things without a problem. If I close out of the form and reopen it I can add a new record without issues. Anyone have ideas?
Using VBA, it's the standard add-new code, nothing else. Posted all the code for this form below. Some of the command buttons listed are in macros, don't know if that makes a difference.
Private Sub add_Click()
DoCmd.GoToRecord , , acNewRec
End Sub
Private Sub edit_info_Click()
Date_of_Echo.Locked = False
ID.Locked = False
AoV.Locked = False
AI.Locked = False
MR.Locked = False
TR.Locked = False
TR_velocity.Locked = False
PA_pressures.Locked = False
LVeDD.Locked = False
LVeSD.Locked = False
RV_function.Locked = False
comments.Locked = False
Me.next.Visible = False
Me.previous.Visible = False
Me.first.Visible = False
Me.last.Visible = False
Me.add.Visible = False
Me.save.Visible = True
Me.save.SetFocus
Me.edit_info.Visible = False
End Sub
Private Sub Form_Current()
If Me.NewRecord Then
Me.recordcounter.Caption = "New Record"
Me.next.Visible = False
Me.previous.Visible = False
Me.first.Visible = False
Me.last.Visible = False
Me.add.Visible = False
Me.edit_info.Visible = False
Me.save.Visible = True
Date_of_Echo.Locked = False
ID.Locked = False
AoV.Locked = False
AI.Locked = False
MR.Locked = False
TR.Locked = False
TR_velocity.Locked = False
PA_pressures.Locked = False
LVeDD.Locked = False
LVeSD.Locked = False
RV_function.Locked = False
comments.Locked = False
Else
Me.recordcounter.Caption = "Record " & Me.CurrentRecord & " of " & Me.Recordset.RecordCount
Me.next.Visible = True
Me.previous.Visible = True
Me.first.Visible = True
Me.last.Visible = True
Me.add.Visible = True
Me.edit_info.Visible = True
Me.save.Visible = False
End If
End Sub
Private Sub save_Click()
DoCmd.save
Me.previous.Visible = True
Me.first.Visible = True
Me.last.Visible = True
Me.next.Visible = True
Me.add.Visible = True
Me.edit_info.Visible = True
Me.recordcounter.Caption = "Record " & Me.CurrentRecord & " of " & Me.Recordset.RecordCount
Me.add.SetFocus
Me.save.Visible = False
Date_of_Echo.Locked = True
ID.Locked = True
AoV.Locked = True
AI.Locked = True
MR.Locked = True
TR.Locked = True
TR_velocity.Locked = True
PA_pressures.Locked = True
LVeDD.Locked = True
LVeSD.Locked = True
RV_function.Locked = True
comments.Locked = True
End Sub
Private Sub next_Click()
On Error GoTo Err_cmdLastRecord_Click
Me.AllowAdditions = False
DoCmd.GoToRecord , , acNext
Exit_cmdLastRecord_Click:
Exit Sub
Err_cmdLastRecord_Click:
MsgBox " There are no more records ", vbExclamation, ""
Resume Exit_cmdLastRecord_Click
End Sub
My first thought is that your record isn't saving before you try to go to a new record so try this and see if it fixes the issue.
Private Sub add_Click()
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.GoToRecord , , acNewRec
End Sub
If anyone is still having this problem, I can't explain why it's happening, but here's a work around:
Reset the AllowAdditionsProperty on the form:
Me.[form_name].Form.AllowAdditions = False
Me.[form_name].Form.AllowAdditions = True
This was a very strange issue because my code had been working fine for weeks. I was using something like this:
Me.frm.SetFocus
DoCmd.GoToRecord , , acNewRec
!Field1 = value1
!Field2 = value2
It was working great, and then out of the blue I started getting the "Can't go to Specified Record" error, even though I had made no changes to the code. The form settings were fine and I could add records all day long in the underlying table. I even checked the form's AllowAdditions property in the Immediate window, and that showed it was set to True. But I tried this work around, and it worked.
Now I add those two lines after every instance of Docmd.GoToNewRoecord, acNewRecord and it's working.
Another thing I have mentioned with the same problem is that you should check the Form data source query. Are all the FIELDS available, are the JOINS correct?
In my case I changed indexed joins from text fields to numeric and it needed update also in Form Data source query.

Access VBA Checkbox error 2447

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.

Sending messages with HTML contents using the MAPI control in VB6

How can I send a mail using MAPI with an HTML body? I need to create table in a message body.
I'm using vb6 and the MAPI control. Any ideas?
Function MailSend(sSendTo As String, sSubject As String, sText As String) As Boolean
On Error GoTo ErrHandler
With MAPISession1
If .SessionID = 0 Then
.DownLoadMail = False
.LogonUI = True
.SignOn
.NewSession = True
MAPIMessages1.SessionID = .SessionID
End If
End With
With MAPIMessages1
.Compose
.RecipAddress = sSendTo
.AddressResolveUI = True
.ResolveName
.MsgSubject = sSubject
.MsgNoteText = sText
.Send False
End With
MailSend = True
Exit Function
ErrHandler:
'MsgBox Err.Description
MailSend = False
End Function
MAPI control uses Simple MAPI, which does not handle HTML. There is a trick when using Simple MAPI directly (MAPISendMail) - set the body to NULL and attach and HTML file: it will be used as the message body. I don't know if that trick will work with the MAPI control.
Why not switch to using the Outlook Object Model? It is perfectly capable of handling HTML:
set App = CreateObject("Outlook.Application")
set NS = App.GetNmaespace("MAPI")
NS.Logon
set Msg = App.CreateItem(0)
Msg.To = sSendTo
Msg.Subject = sSubject
Msg.HTMLBody = sYourHTMLBody
Msg.Send 'or Msg.Display
keep
.MsgNoteText ="";
.AttachmentPathName = result
ie.
With MAPIMessages1
.Compose
.RecipAddress = sSendTo
.AddressResolveUI = True
.ResolveName
.MsgSubject = sSubject
.MsgNoteText =""
.AttachmentPathName = "c:\yourHtml.html"
.Send False
End With

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.