My company has recently upgraded from MS Access 2013 to MS Access 365. I have about 23 databases and only 2 of them are acting up. The following code is almost exactly the same in all databases except for what happens inside the IF statement.
Private Sub cmbSelectProf_AfterUpdate()
gUName = [cmbSelectProf]
Call globalOfficerInfoSelection
gVCredit = Val(gCredit)
gVAdmin = Val(gAdmin)
If gVCredit = 33 Then
DoCmd.OpenForm "Main"
DoCmd.ApplyFilter "UndQryCorp"
DoCmd.GoToRecord , , acNewRec
Else
MsgBox ("You have not been given CDS Maker permission. Please contact Credit Administration")
Application.FollowHyperlink "\\appsrv03\apps\CreditApplications\SwitchBoardMain2013_v2.accdb"
DoCmd.Quit
End If
Forms![officer switchboard].Visible = False
End Sub
The issue comes at the very end when I try to hide the [officer switchboard]. Some databases it hides it and some it doesn't. If I Debug the VBA and step through the code it will hide it without me changing anything. Below is code of a database that the Visible property does work.
Private Sub cmbSelectProf_AfterUpdate()
gUName = [cmbSelectProf]
Call globalOfficerInfoSelection
gVCredit = Val(gCredit)
gVAdmin = Val(gAdmin)
gVOfficerID = Val(gOfficerID)
If gRM = 2 Then
DoCmd.OpenForm "CutMain"
DoCmd.ApplyFilter "CutMainOfficer_filter"
DoCmd.GoToRecord acDataForm, "CutMain", acNewRec
DoCmd.GoToRecord acDataForm, "CutMain", acNewRec
Else
DoCmd.OpenForm "Cutmain"
DoCmd.GoToRecord acDataForm, "CutMain", acNewRec
End If
Forms![officer switchboard].Visible = False
End Sub
Related
I am running into a 2467 error after the following code ():
Option Compare Database
Option Explicit
Private Sub CmdReject_Click()
Dim lngID As Long
lngID = Me.ID
If Me.Dirty Then Me.Dirty = False
DoCmd.Close , ""
Beep
MsgBox "Issue has been saved.", vbInformation, ""
NewFormIssue (lngID)
End Sub
Private Sub NewFormIssue(lngID As Long)
DoCmd.OpenForm "Frm_Issue_Entry", acNormal, , , acFormAdd
Me.Person.Value = DLookup("[Previous_Person]","[tbl_Issue_Log]", "[ID] = " lngID)
End Sub
The run-time error occurs during the Me.Person.Value = DLookup("[Person]","[tbl_Issue_Log]", "[ID] = " lngID) line.
I am trying to use the ID of the previous form to populate 11 fields on this new form so the user doesn't have to redo everything using dlookup, which worked before but I can't seem to find why it just stopped working...
I think I figured out what was happening (at least from a high level standpoint). The Me was still pointing to the previously closed form, not the new form added, causing the error. I fixed the issue by using Form_Frm_Issue_Entry.Person.Value instead, but I am not sure why it worked previously.
I am trying to have a template form that will load setting from tables. For example i will have a master table with different form IDs and then a textbox table that will have a list of textboxes with what form ID they belong too, their position, their value, and etc. The issue is when i open the form in design mode the code doesn't run and if I try and set the view to design mode i get and error saying "you cant switch to a different view at this time" with a code of 2174. here is the code i am using right now, all the values are hard coded so i know i don't have any errors with the reading from the database or anything. Any help is greatly appreciated!
Option Compare Database
Private Sub Form_Load()
loadSettings
End Sub
Private Sub loadSettings()
Dim ctl As Access.Control
On Error GoTo ERR_Line
DoCmd.RunCommand acCmdDesignView
Set ctl = CreateControl(Me.Name, acTextBox, acDetail, , , 100, 100, 100, 100)
ctl.Name = "txt1"
ctl.Value = "test"
DoCmd.RunCommand (acCmdFormView)
ERR_Line:
MsgBox Err.Description & " Error Number " & Err
End Sub
If i use a module with this code in it, it will go into design mode but gives a "Microsoft Access cant add, rename, or delet the control(s) you requested." error number 29054.
Option Compare Database
Sub loadSettings(frmName As String)
Dim frm As Form
Dim ctl As Access.Control
On Error GoTo ERR_Line
Set frm = Application.Forms(frmName)
DoCmd.Close acForm, frmName
DoCmd.OpenForm frmName, acDesign
Set ctl = CreateControl(frmName, acTextBox, acDetail, , , 100, 100, 100, 100)
ctl.Name = "txt1"
ctl.Value = "test"
DoCmd.Close acForm, frmName, acSaveYes
DoCmd.OpenForm frmName, acNormal, , , , , "asdf"
ERR_Line:
MsgBox Err.Description & " Error Number " & Err
End Sub
I have been working on this problem for a while and I'm close to the answer thanks to the help of stack overflow and google. Let me give you some insight. I have a table and 2 forms and a Key named CalibrationKey that auto increments as a Autonumber to keep track of the record and how many and what not. On 1 form are all my table fields. On my 2nd form is the Subfields to the first form that feed into the table. First form is Calibration and 2nd form is Calibration Detail. In my first form, I have it so you can edit OR add a new record(where my problem started). My 2nd form I have it so you can only add a new record and have the Data Entry on Property Sheet to YES as I only want you to be able to add a new record from that form. So I made a If Else statement as a click event in my First Form that if my Text box is Empty, then you add a new record. If it is NOT empty, then you edit the form. But, I get a Syntax error every time I try and do this. I'm not sure what the problem is.
Private Sub Make_Click()
If Not IsNull(Make.Value) Then
DoCmd.OpenForm "Calibration Detail", , , "[CalibrationKey]= " & Me.[CalibrationKey], acFormAdd, acDialog
Else: DoCmd.OpenForm "Calibration Detail", , , "[CalibrationKey]= " & Me.[CalibrationKey], acFormEdit, acDialog
End If
End Sub
Then I found that a IsEmpty might be easier, but it gives the same Syntax error in the ELSE line of code as the Not IsNull line did.
Private Sub Make_Click()
If IsEmpty(Make.Value) Then
DoCmd.OpenForm "Calibration Detail", , , "[CalibrationKey]= " & Me.[CalibrationKey], acFormAdd, acDialog
Else: DoCmd.OpenForm "Calibration Detail", , , "[CalibrationKey]= " & Me.[CalibrationKey], acFormEdit, acDialog
End If
End Sub
Trying to diagnose the problem of the incorrect Syntax as Either IsEmpty or Not IsNull seems to give the same syntax error on the same line. Looking to correct the syntax error and which is function is better to use, rather it be IsEmpty, or Not IsNull
Try using the normal If-Then-Else syntax:
Private Sub Make_Click()
Dim DataMode As acFormOpenDataMode
If Me.Dirty = True Then
'Save record.
Me.Dirty = False
End If
If Not IsNull(Make.Value) Then
DataMode = acFormOpenDataMode.acFormAdd
Else
DataMode = acFormOpenDataMode.acFormEdit
End If
DoCmd.OpenForm "Calibration Detail", , , "[CalibrationKey]= " & Me.[CalibrationKey], DataMode, acDialog
End Sub
[Disclaimer: I'm self-taught and a total novice!]
I have a FORM with which a QUERY pulls data and uses it to populate a REPORT. As the end user finishes the report and clicks a button, the following is supposed to happen:
1) The FORM saves all the data in a new record on the TABLE 2) A query pulls that record by the ID (which is autonumbered) from the FORM 3) The QUERY populates a REPORT with the data from the TABLE 4) The FORM and QUERY close - no need to save.
The QUERY pulls all the data from the corresponding TABLE with the following criteria: [Forms]![Data_Input_Form]![ID]
However, my REPORT comes up blank! Eek!
I have a similar QUERY that pulls data from the same TABLE and populates it to a similar REPORT with the following criteria: Like Nz([Forms]![Home_Form]![Incident_ID_Lookup_text],"*")
Unsurprisingly, when I added this to the QUERY that wasn't working how I wanted it to, it reported ALL the previous records.
'------------------------------------------------------------
' Add Report [and Open Report] Button Click
'
'
'------------------------------------------------------------
Private Sub Add_Rpt_Btn_Click()
If MsgBox("Are you sure? No backsies.", vbYesNo, "Add Report?") = vbNo Then
Exit Sub
End If
'Check for Necessary Fields and Add New Record
If (IsNull(Me.Person_Filing) Or IsNull(Me.Nature_Lst) Or IsNull(Me.Location_Cmb) Or IsNull(Me.Summary) Or IsNull(Me.Narrative)) = True Then
MsgBox "Looks like you left some important information out. Please fill out all fields with an asterisk.", vbOKOnly, Whoops
Exit Sub
Else
DoCmd.GoToRecord , , acNewRec
End If
'Run Query to Open Report
DoCmd.OpenQuery "Form_to_Report_Qry"
DoCmd.OpenReport "Incident_Report_1", acViewReport, , [ID] = [Forms]![Data_Input_Form]![ID]
'Close Query without Saving
DoCmd.Close acQuery, "Form_to_Report_Qry", acSaveNo
'Close Form without Saving
DoCmd.Close acForm, "Data_Input_Form", acSaveNo
End Sub
The REPORT needs to populate with the most recent record, but it keeps coming up blank.
That's because you move a new (empty) record - having no ID.
I guess, all you need is to use the current ID of the form - and use the correct syntax for the filter:
Private Sub Add_Rpt_Btn_Click()
If MsgBox("Are you sure? No backsies.", vbYesNo, "Add Report?") = vbNo Then
Exit Sub
End If
' Check for Necessary Fields and Add New Record
If (IsNull(Me.Person_Filing) Or IsNull(Me.Nature_Lst) Or IsNull(Me.Location_Cmb) Or IsNull(Me.Summary) Or IsNull(Me.Narrative)) = True Then
MsgBox "Looks like you left some important information out. Please fill out all fields with an asterisk.", vbOKOnly, Whoops
Exit Sub
End If
' If not saved, save the current record.
If Me.Dirty = True Then
Me.Dirty = False
End If
DoCmd.OpenReport "Incident_Report_1", acViewReport, , "[ID] = " & Me![ID].Value & ""
' Close Form without Saving
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub
I am setting up a database containing patient information. Right now, users can navigate to a particular patients information (Patient Home Page) using a search/confirm form. The Home Page has links to other forms with additional patient information. The code works when users search for a patient that was put in from the beginning (aka the "patients" I put in as test people at the beginning will show up and the code behaves as it is supposed to). However, when I try to add a new patient, the confirmation form will no longer work. The new record is created in the patient list table and the search form will find the new patient, but when I click on the continue button on the confirmation form, the Patient Home Page pulls up as a new (blank) record. The code only breaks with new patients.
I am also having an issue creating a new record in the "Equipment Log" form when I add a new patient to the home page form. I have a 1-to-1 relationship between the equipment log and patient home page, with pt ID being the primary key for both tables. When I add a new patient through the "pt home page", I need to create a linked record in the equipment log that is connected via the pt ID. So far, I have tried code similar to that found below and other similar things, but nothing seems to work.
Code for the search and confirmation pages are below, as well as part of the code for the patient home page (although I don't know that that code is very useful). Any help is appreciated, I've been stuck on this for awhile.
Patient Search Page:
Private Sub Patient_Search_Click()
On Error GoTo Patient_Search_Click_Err
DoCmd.OpenForm "Confirmation", acNormal, "", "", acReadOnly, acNormal
Patient_Search_Click_Exit:
Exit Sub
Patient_Search_Click_Err:
MsgBox Error$
Resume Patient_Search_Click_Exit
End Sub
Private Sub add_new_Click()
On Error GoTo add_new_Click_Err
' _AXL:<?xml version="1.0" encoding="UTF-16" standalone="no"?>
' <UserInterfaceMacro For="Patient Search" Event="OnClick" xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application" xmlns:a="http://schemas.microsoft.com/office/accessserv
' _AXL:ices/2009/11/forms"><Statements><Action Name="OpenForm"><Argument Name="FormName">Confirmation</Argument><Argument Name="DataMode">Read Only</Argument></Action></Statements></UserInterfaceMacro>
DoCmd.OpenForm "Patient Home Page"
DoCmd.GoToRecord , , acNewRec
add_new_Click_Exit:
Exit Sub
add_new_Click_Err:
MsgBox Error$
Resume add_new_Click_Exit
End Sub
Patient Confirmation Page (*Note: I edited this and added a breakpoint at the debug.print. When I run the command nothing prints and now nothing will open)
Private Sub confirm_Click()
testid = [Patient List_ID]
Debug.Print
DoCmd.OpenForm "Patient Home Page", acNormal, "", "[ID]=" & "'" & [Patient List_ID] & "'"
End Sub
Patient Home Page:
Private Sub Form_Current()
If Me.NewRecord Then
Me.equipment_log.Visible = False
Me.echos.Visible = False
Me.open_logs.Visible = False
Me.openadvisory.Visible = False
Me.save.Visible = True
Me.edit.Visible = False
Me.cancelupdate.Visible = True
Last_Name.Locked = False
First_Name.Locked = False
Middle_name.Locked = False
Device.Locked = False
Patient_List_ID.Locked = False
MRN.Locked = False
DOB.Locked = False
Implant_Date.Locked = False
Transplant_Goal.Locked = False
Status.Locked = False
Caregiver.Locked = False
Address.Locked = False
City.Locked = False
State.Locked = False
Zipcode.Locked = False
Phone_1.Locked = False
Phone_2.Locked = False
Phone_3.Locked = False
Else
Me.equipment_log.Visible = True
Me.echos.Visible = True
Me.open_logs.Visible = True
Me.openadvisory.Visible = True
Me.save.Visible = False
Me.edit.Visible = True
Me.cancelupdate.Visible = False
Last_Name.Locked = True
First_Name.Locked = True
Middle_name.Locked = True
Device.Locked = True
Patient_List_ID.Locked = True
MRN.Locked = True
DOB.Locked = True
Implant_Date.Locked = True
Transplant_Goal.Locked = True
Status.Locked = True
Caregiver.Locked = True
Address.Locked = True
City.Locked = True
State.Locked = True
Zipcode.Locked = True
Phone_1.Locked = True
Phone_2.Locked = True
Phone_3.Locked = True
End If
End Sub
Create new record in equipment log from new entry in patient list (inside of if statement for create new record)
Dim crit As String
crit = [Patient List_ID]
DoCmd.OpenForm "Patient Equipment Log"
DoCmd.GoToRecord , , acNewRec
Forms![Patient Equipment Log]![Patient Equipment.ID] = crit
From the sounds of it your new patients aren't being saved before you try to open up a form to view them. So basically you create a new patient and tell a second form to view that patient before they ever actually "exist" in the database's eyes.
Private Sub Patient_Search_Click()
On Error GoTo Patient_Search_Click_Err
DoCmd.Save
DoCmd.OpenForm "Confirmation", acNormal, "", "", acReadOnly, acNormal
Patient_Search_Click_Exit:
Exit Sub
Patient_Search_Click_Err:
MsgBox Error$
Resume Patient_Search_Click_Exit
End Sub
I finally got it...apparently somewhere I had the equipment and patient lists related by MRN. I added an if statement under the "save" command on the patient home page to check if there was a record with an identical MRN in the patient equipment list. If not, I created a new record.
Private Sub save_Click()
DoCmd.save
Dim crit As String
crit = [Patient List_ID]
DoCmd.OpenTable "Patient Equipment"
qcrit = DLookup("[ID]", "Patient Equipment", "[Patient List_ID]=" & "'" & crit & "'")
If StrComp(crit, qcrit) = 0 Then
DoCmd.Close
Else
DoCmd.OpenForm "Patient Equipment Log"
DoCmd.GoToRecord , , acNewRec
Forms![Patient Equipment Log]![MRN] = Forms![Patient Home Page]![MRN]
Forms![Patient Equipment Log]![Patient Equipment.ID] = Forms![Patient Home Page]![Patient List_ID]
Forms![Patient Equipment Log]![Implant Date] = Forms![Patient Home Page]![Implant Date]
DoCmd.Close
End If