Quantcast
Channel: Access for Developers forum
Viewing all 14673 articles
Browse latest View live

Front End Access DB constantly getting "inconsistent state" error when more than 1 user opens it

$
0
0

Front end: 2013 Access stored on Windows 2012 files server.  Physical Server with 4 x NIC Team

Back end:  Windows 2012, SQL 2012 Standard.  Physical Server with 4 x NIC Team

Multiple users share front end Access DBs connect to back end SQL.  It's been working well for the past few years, but since early May, if 2 or more users opens the .accdb file, when 1 closes out, they get an error "A problem occurred with removal of personal information from this file. Some personal information may not have been removed".  This happens even if user didn't make any changes.  Once this happens, the next person tries to open the DB gets the database is inconsistent state, and Access locks up on user's computer.  Only way to fix is to get everyone out of the DB and repair.  

Have verified network traffic and hard disk utilization are fine, no hardware errors on either file or SQL server.  Only change made is Microsoft Office patches released around May 1st.  

Wondering if anyone experienced similar issues in the past and know of a fix.  Thanks in advance.


Roget Luo


Insert into a table from a subform and another table access vba

$
0
0

I have a table `StdCourseLevel` with the following fields:

StudentID    LevelID   YearID    CourseID    Credit

and a subform `StdLevelYearSub` placed in a form `Students`. The subform having the fields

StudentID    LevelID   YearID
and also a table `LevelCourse` with the fields:
LevelID      CourseID       Credit

 

so when a user enter data (StudentID, LevelID, YearID) into the subform , these three values PLUS the two values (CourseID and Credit) from LevelCourse should be inserted into StdCourseLevel when

LevelCourse.[LevelID] = StdLevelYearSub.[LevelID]

Any help is appreciated


Access 2016 - Microsoft Script Control stopped working (Error 380)

$
0
0

I have an Access Solution using VBA.

This solution is using Microsoft Script Control 1.0 (msscript.ocx) and everything was working for years. But now it suddenly stopped working.

Access 2016 (V 1806 - Build 10228.20080) now throws runtime error '380' - 'A script engine for the specified language can not be created.'

Very oddly, this error occurs ONLY in Access 2016 (starting from about last week), the same code in Excel 2016 or Access 2013, Access 2010 runs without any problem.

I have a strong intuition that the problem was introduced by one a recent '*nice*' auto-updates from MS. Indication: The error started to occur last week. One computer that was not restarted worked as previously, after a restart the runtime error 380 occurred also on that machine. The problem occurs also on a freshly installed Windows 10 machine with current Office 365.

Here is the very simple code that produces the error on Access 2016.

Public Sub TestScriptControl()
    Dim oScript As New ScriptControl
    With oScript
        .Language = "VBScript"  '<<<----- ERROR 380 in Access 2016 (V 1806 - Build 10228.20080)
                                'NO Problem in Excel 2016, prior Versions of Access (2010 or 2013)
        .AddCode "Public Function MyTest() " & vbCrLf _& "MsgBox ""Hat funktioniert!""" & vbCrLf _& "End Function"
        .Run "MyTest"
    End With
End Sub


Any help is very much appreciated!

Update 2018/07/10: To my understanding the current status is as follows: 

  • The problem was introduced with Office 365 V 1806, Build 10228.20080.
  • Affected is only the scripting engine for VBA (JavaScript) still works.
  • COM-Addins are also affected.
  • A confirmed remedy is to revert to Version 1805 (Build 9330.2124) and to and to turn auto-updates off for Office. This is how to revert the office version
  • At least for COM-Addins changing the registry-keys for HKLM\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\Software\Microsoft\Office\16.0\Common\COM Compatibility\{B54F3741-5B07-11cf-A4B0-00AA004A55E8}
    "ActivationFilterOverride"=dword:00000001 and the corresponding \Wow6432Node seems to work also (see Process4.biz GmbH Post below). (for VBA this change is not yet confirmed)

BeforeUpdate triggering twice due to updating bound field

$
0
0

When an update is made, this application displays a prompt saying something like "You have made an update, do you want to save or not". When they click 'Yes', validations are performed and if they all pass, the 'Last Updated' and LastUpdated By' fields get updated as the last step in Before Update.

What is happening is the "save or not" prompt is displaying twice. After stepping through the logic, the BeforeUpdate event is being triggered twice. The only reason I can deduce for this is that my updating the 'Last Updated' fields (which are bound fields) is causing the triggering. The re-triggering happens upon running DoCmd.Close statement.

Does anyone know how I can update these two fields without re-triggering the Before Update event and all my validations?

Report field off screen causing Type error

$
0
0

2010 & 2013 accdb;  have Form 1 that is calling value from Report A i.e. =Reports!ReportA.FieldZ

Field Z is in the report footer

In the report detail section is a continuous style that can have a random set of rows - and the sum of a field in the rows is occurring in the report footer by Field Z.

so far so good.  Form 1 always gets opened after Report A is opened.  That's set.

I have discovered that if Report A has many rows and is quite tall in height (pushing down the report footer to not within visual area) - that Form 1 field will open to Type error when calling to the Report's Field Z.

I have sanity checked this two ways; first just by going back and forth between jobs with an average amount of rows and one with an unusually large set of rows.  It is not the exact visual area, as scrolling is needed in both cases.  But more scrolling is needed for the job that causes the error; only the large set causes an error to be thrown.  

                                                      second, by coincidence, in this application there is removed/hidden the ribbon.  in the job with an unusually large set of rows it only throws this error when the ribbon is displayed (the mode I work in) but not when the ribbon is removed/hidden....effectively re-sizing the report's visual area just enough to be the difference here.  This is what has led me to believe that the field Z is sufficiently far off screen as to not be firing - and thus the type error in Form 1 when it opens.

comments on this would be welcomed; haven't run across this before and it means that the convenience of re-using report field Z will need to be dropped in favor of another data source....

set the default of a field based on another field

$
0
0
in the form, i have a check box to be checked if an item is selected. Once that is checked, the value of another field should be set to it's default value as a placeholder. its final value will be determined later from the options in the combo box.

Access 2016 Navigation Form: Navigation buttons appear selected when they are not.

$
0
0

In a new Access 2016 project I have a new navigation form that I created via: Create > Navigation > Vertical tabs, Left. I set up some buttons and when I tested it in form view the buttons don't behave like they should.

If I click through all the options the buttons appear to stay selected when they are not and this visual state is cleared by the highlight function of waving the mouse over the buttons.

How do I stop this and get normal button behavior?

Hyperlink fields

$
0
0

Access VBA:

Private Sub HyperlinkTest

dim rst as recordset 'based on a tabledef  --  fields(12) defined as Hyperlink

dim link as hyperlink

'code to seek record here

'How to code the following?

link = rst.fields(12)


Access crashes when moving items inside a Macro

$
0
0

I have Office Professional Plus 2016 and when working with Macros in Access (editing) when I more items order most of the time Access crashes.

I uninstalled and installed access, I did a repair (normal and online), I even installed the 64 bit version and nothing has fixed the problem.

The error says "Access has encountered a problem..." and then reopens Access and gives me an option to save the file as a backup.

I also tried the compact/repair database and nothing has fixed it.

It is becoming extremely annoying and slows production to have access crash so often.  Another person reported this under the title "Access 365 crashes when editing/saving/closing macros" but there were no follow ups. Any help is appreciated

QueryDef with ALTER TABLE ADD column statement

$
0
0

Hello,

I am trying to use Query Def for the first time to create a query that will then alter a table by adding columns. This functionality will allow users of a Ms Access database to modify a temporary table by adding columns to it via a form. The form will have a list of options to select. Once the users clicks on a button, the code will add these options one at a time as columns to the table. I'll create a loop for this to happen. The table will also be dropped and recreated with the standard parameters. So the steps are:

1 User selects options

2 User clicks alter table button

3 Table is recreated with standard parameters

4 Table has column added with first of user's selections by having a query that is programmatically edited

5 Loop until all selections have been added as columns to table

6 Form displays table for user to enter data

7 Submit button will extract user's data and enter into a standardized table

8 End

I need help with number 4. This is what I came up

Private Sub Command0_Click()
    Dim qdfNew As QueryDef
    Set qdfNew = .CreateQueryDef("qtyAlterTable", "ALTER TABLE tempRoomFeature ADD qryRoomFilter.Room integer")
End Sub

tempRoomFeature is the name of the table in question

qryRoomFilter is the name of the query providing the first of the user's selctions

Room is the name of the field produced by query qryRoomFilter

Thanks for your help.

Link Azure SQL Tables to Access 2016 Database

$
0
0

I am trying to link Azure SQL tables to an Access 2016 Database.

Azure SQL does not support Trusted_Connection=Yes or Integrated Security=SSPI and ignores  the User ID and Password fields in the ODBC connection string. A credentials dialog opens even though there is a User ID and Password specified.

Below is an Access 2016 VBA button click event handler that demonstrates the problem.

-----------------------

Private Sub Link_Table_Click()
On Error GoTo Link_Table_Click_Err

    Dim MyTable As TableDef, ConnectionString As String
    Set MyTable = CurrentDb.CreateTableDef("ATableList")
    MyTable.SourceTableName = "ATableList"
    ConnectionString = "ODBC;Driver={SQL Server Native Client 11.0};Server=tcp:azureserver.database.windows.net,1433;"
    ConnectionString = ConnectionString & "User ID={userid};Password={password};"
    ConnectionString = ConnectionString & "APP=Microsoft Office 2016;"

    ConnectionString = ConnectionString & "LANGUAGE=us_english;DATABASE=PPMLocal;Table=dbo.ATableList"
    MyTable.Connect = ConnectionString
    CurrentDb.TableDefs.Append MyTable
    RefreshDatabaseWindow

Link_Table_Click_Exit:
    Exit Sub

Link_Table_Click_Err:
    MsgBox Error$
    Resume Link_Table_Click_Exit

End Sub

-----------------------

I would appreciate any suggestions on how to link Azure SQL tables without the need to enter credentials via a dialog box.

Thank you.

Compact & Repair changes database VERSION?

$
0
0

Front ends named FE5j.accdb on several clients linked to TheBackEnd.accdb on a Windows 7 network maintained by a third party, who have apparently "changed some things".

BE was ~34MB on the server. I took a copy home. C&R reduced the size to ~23MB, so I knew the version on the server could be cleaned up. Which I did.

At the end of the process, Access produced an error message to the effect that it could not rename Database.mdb to TheBackEnd.mdb, and explained how C&R makes a copy first, then does the compaction, then does a name change. Notice that it was trying to change the file extension. What!?

I manually changed the file name and relinked the databases on 3 machines, which means there are still a few clients that need relinking.

The BE is now named TheBackEnd.mdb, which A2010 can read, and there’s nothing in there that’s peculiar to A2010, so it should be good to go, but this is just weird.


peter n roth - http://PNR1.com, Maybe some useful stuff

MS Access SQL Query Issue - Inner Joins

$
0
0

Hi Folks -

I have a query powered by a SQL statement that works perfectly - it is as follows:

SELECT New_PFC_Request.N_Alias
, New_PFC_Request.N_Parent_Mode
, UserInfo.Name
, UserInfo.[Work Email]
, New_PFC_Request.Modified
, New_PFC_Request.Request_Status
FROM New_PFC_Request INNER JOIN UserInfo ON New_PFC_Request.[Created By] = UserInfo.ID
WHERE ( New_PFC_Request.Request_Status = 'Completed' OR  New_PFC_Request.Request_Status = 'Rejected');

However, I want to add a new column sourced from another table called PFC_RD_3Level_Flat_Expanded.[Compound Code].

Now, New_PFC_Request.N_Alias is equal to PFC_RD_3Level_Flat_Expanded.[Compound Alias]  therefore I tried to modify the code as such but it's throwing errors:

SELECT PFC_RD_3Level_Flat_Expanded.[Compound Code] as Code , New_PFC_Request.N_Alias , New_PFC_Request.N_Parent_Mode , UserInfo.Name , UserInfo.[Work Email] , New_PFC_Request.Modified , New_PFC_Request.Request_Status FROM New_PFC_Request INNER JOIN UserInfo ON New_PFC_Request.[Created By] = UserInfo.ID

INNER JOIN PFC_RD_3Level_Flat_Expanded ON PFC_RD_3Level_Flat_Expanded.[Compound Alias] = New_PFC_Request.N_Alias WHERE ( New_PFC_Request.Request_Status = 'Completed' OR New_PFC_Request.Request_Status = 'Rejected');


Can anyone assist? Thank you!



This code doesn't work when I have two or more table in my form Recordsource

$
0
0

 I use this code for making forms for searching  in my Access program.My backend database is SQL. When the record source of this forms is only one table , for example "Customers" it works properly and I search anythings very well, but when I made forms that has two or more tables as record source, it encounter a problem. It trigger error 2474 and error 2185 , it occurs when the code doesn't find the matching text that I entered in the text box  in the underlying tables (field). I tried a lot but haven't find what is the problem!

I used this code in my Access program when its back end database was Access, for making search forms and it worked properly but when I migrated my database to SQL it trigger this error.


Option Compare Database
Option Explicit

'Configuration options
Private Const mbcStartOfField = False   'True to match only the start of the field; False for anywhere in field.
Private Const mstrcWildcardChar = "%"   'Pattern matching wildcard. "*" for Access. "%" for SQL Server.
Private Const mstrcSep = ";"            'Separator between list items. May need changing for some regional settings.

'Columns of cboFindAsUTypeField
Private Const micControlName = 0
Private Const micControlLabel = 1
Private Const micControlType = 2
Private Const micFilterField = 3
Private Const micFieldType = 4

'Constant to indicate a control is sitting on the form (not on the page of a tab control.)
Private Const mlngcOnTheForm = -1&

'Module name (for error handler.)
Private Const conMod = "ajbFindAsUType"

Public Function FindAsUTypeLoad(frm As Form, ParamArray avarExceptionList()) As Boolean
On Error GoTo Err_Handler
    'Purpose:   Initialize the code for Find.
    'Return:    True on success.
    'Arguments: - frm = a reference to the form where you want this filtering.
    '           - Optionally, you can specify controls NOT to offer filtering on, by putting the control names in quotes.
    'Note:      The form must contain the 2 controls, cboFindAsUTypeField and txtFindAsUTypeValue,
    '               with the combo set up correctly.
    'Usage:     Set the Load event procedure of the form to:
    '               Call FindAsUType(Me)
    '           To suppress filtering on controls FirstName and City, use:
    '               Call FindAsUType(Me, "FirstName", "City")
    Dim rs As DAO.Recordset             'Clone set of the form.
    Dim ctl As control                  'Each control on the form.
    Dim strForm As String               'Name of form (for error handler.)
    Dim strControl As String            'Name of the control.
    Dim strField As String              'Name of the filter to use in the filter string.
    Dim strControlSource As String      'Name of the field the control is bound to.
    Dim strOut As String                'List for the RowSource of cboFindAsUTypeField.
    Dim lngI As Long                    'Loop counter.
    Dim lngJ As Long                    'Page counter loop controller.
    Dim bSkip As Boolean                'Flag to provide no filtering for this control.
    Dim bResult As Boolean              'Return value for this function.
    Dim lngParentNumber As Long         '-1 if the control is directly on the form, else PageIndex of it parent.
    Dim lngMaxParentNumber As Long      'PageIndex of last page of tab control. -1 if no tab control.
    Dim astrControls() As String        'Array to handle the controls on the form.
    Const lngcControl = 0&              'First element of array astrControls is the control name.
    Const lngcField = 1&                'Second element of the array is the field name to filter on.
    'The form must have a control source if we are to filter it, and needs our 3 controls.
    strForm = frm.Name
    If HasUnboundControls(frm, "cboFindAsUTypeField", "txtFindAsUTypeValue") And (frm.RecordSource <> vbNullString) Then
        'Set the event handers for the 2 contorls
        frm!cboFindAsUTypeField.AfterUpdate = "=FindAsUTypeChange([Form])"
        frm.txtFindAsUTypeValue.OnChange = "=FindAsUTypeChange([Form])"
        'Calculate the number of pages on the tab control if there is one.
        lngMaxParentNumber = MaxParentNumber(frm)
        'Declare an array large enough to handle the controls on the form,
        '   for each page of any tab control (since these have their own tab index),
        '   and for storing the control name and the filter field name.
        ReDim astrControls(0& To frm.Controls.Count - 1&, mlngcOnTheForm To lngMaxParentNumber, lngcControl To lngcField) As String
        Set rs = frm.RecordsetClone             'For info about the fields the controls are bound to.
        'Loop through the controls on the form.
        For Each ctl In frm.Controls
            'Ignore hidden controls, and limit ourselves to text boxes and combos.
            If ctl.Visible Then
                If (ctl.ControlType = acTextBox) Or (ctl.ControlType = acComboBox) Then
                    bSkip = False
                    strField = vbNullString
                    strControl = ctl.Name
                    'Ignore if the control name is in the exception list.
                    For lngI = LBound(avarExceptionList) To UBound(avarExceptionList)
                        If avarExceptionList(lngI) = strControl Then
                            bSkip = True
                            Exit For
                        End If
                    Next
                    If Not bSkip Then
                        'Ignore if unbound, or bound to an expression.
                        strControlSource = ctl.ControlSource
                        If (strControlSource = vbNullString) Or (strControlSource Like "=*") Then
                            bSkip = True
                        Else
                            'Ignore yes/no fields, binary (JET uses for unknown), and complex data types (> 100.)
                            Select Case rs(strControlSource).Type
                            Case dbBoolean, dbLongBinary, dbBinary, dbGUID, Is > 100
                                bSkip = True
                            End Select
                        End If
                    End If
                    'Ignore if we cannot specify the field to filter on.
                    If Not bSkip Then
                        strField = GetFilterField(ctl)
                        If strField = vbNullString Then
                            bSkip = True
                        End If
                    End If
                    'Add this control name to our array, in the order of the tab index.
                    If Not bSkip Then
                        lngParentNumber = ParentNumber(ctl)
                        astrControls(ctl.TabIndex, lngParentNumber, lngcControl) = strControl
                        astrControls(ctl.TabIndex, lngParentNumber, lngcField) = strField
                    End If
                End If
            End If
        Next
        'Loop through the array of controls, to build the string for the RowSource of cboFindAsUTypeField (5 columns.)
        For lngJ = LBound(astrControls, 2) To UBound(astrControls, 2)
            For lngI = LBound(astrControls) To UBound(astrControls)
                If astrControls(lngI, lngJ, lngcControl) <> vbNullString Then
                    Set ctl = frm.Controls(astrControls(lngI, lngJ, lngcControl))
                    strOut = strOut & """" & ctl.Name & """" & mstrcSep & _"""" & Caption4Control(frm, ctl) & """" & mstrcSep & _
                        ctl.ControlType & mstrcSep & _"""" & astrControls(lngI, lngJ, lngcField) & """" & mstrcSep & _"""" & rs(ctl.ControlSource).Type & """" & mstrcSep
                End If
            Next
        Next
        rs.Close
        'Remove the trailing separator, and assign to the RowSource of cboFindAsUTypeField.
        lngI = Len(strOut) - Len(mstrcSep)
        If lngI > 0 Then
            With frm.cboFindAsUTypeField
                .RowSource = Left(strOut, lngI)
                .Value = .ItemData(0)           'Initialize to the first item in the list.
            End With
            bResult = True            'Return True: the list loaded successfully.
        End If
    End If
    'Show the filter controls. (Separate routine, since they could fail if the control does not exist.)
    Call ShowHideControl(frm, "cboFindAsUTypeField", bResult)
    Call ShowHideControl(frm, "txtFindAsUTypeValue", bResult)
    'Return value
    FindAsUTypeLoad = bResult

Exit_Handler:
    Set ctl = Nothing
    Set rs = Nothing
    Exit Function

Err_Handler:
    Call LogError(Err.Number, Err.Description, conMod & ".FindAsUTypeLoad", "Form " & strForm)
    Resume Exit_Handler
End Function

Public Function FindAsUTypeChange(frm As Form) As Boolean
On Error GoTo Err_Handler
    'Purpose:   Filter the form, by the control named in cboFindAsUTypeField and the value in txtFindAsUTypeValue.
    'Return:    True unless an error occurred.
    'Usage:     The code assigns this to the Change event of the text box, and the AfterUpdate event of the combo.
    Dim strText As String       'The text of the text box.
    Dim lngSelStart As Long     'Selection Starting point.
    Dim strField As String      'Name of the field to filter on.
    Dim bHasFocus As Boolean    'True if the text box has focus (since it can be called from the combo too.)
    Const strcTextBox = "txtFindAsUTypeValue"

    'If the text box has focus, remember the selection insert point and use its Text. Otherwise use its Value.
    bHasFocus = (frm.ActiveControl.Name = strcTextBox)
    If bHasFocus Then
        strText = frm!txtFindAsUTypeValue.Text
        lngSelStart = frm!txtFindAsUTypeValue.SelStart
    Else
        strText = Nz(frm!txtFindAsUTypeValue.Value, vbNullString)
    End If
    
    'Save any uncommitted edits in the form. (This loses the insertion point, and converts Text to Value.)
    If frm.Dirty Then
        frm.Dirty = False
    End If
    
    'Read the filter field name from the combo.
    strField = Nz(frm.cboFindAsUTypeField.Column(micFilterField), vbNullString)
    
    'Unfilter if there is no text to find, or no control to filter. Otherwise, filter.
    If (strText = vbNullString) Or (strField = vbNullString) Then
        frm.FilterOn = False
    Else
        frm.Filter = strField & " Like """ & IIf(mbcStartOfField, vbNullString, mstrcWildcardChar) & _
            strText & mstrcWildcardChar & """"
        frm.FilterOn = True
    End If
    'If the control had focus, restore focus if necessary, and set the insertion point.
    If bHasFocus Then
        If frm.ActiveControl.Name <> strcTextBox Then
            frm(strcTextBox).SetFocus
        End If
        If strText <> vbNullString Then
            frm!txtFindAsUTypeValue = strText
            frm!txtFindAsUTypeValue.SelStart = lngSelStart
        End If
    End If
    'Return True if the routine completed without error.
    FindAsUTypeChange = True

Exit_Handler:
    Exit Function

Err_Handler:
    Select Case Err.Number
    Case 2474
        Resume Next
    Case 2185   'Text box loses focus when no characters left.
        Resume Exit_Handler
    Case Else
        MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "txtFindAsUTypeValue_Change"
        Resume Exit_Handler
    End Select
End Function

Private Function Caption4Control(frm As Form, ctl As control) As String
On Error GoTo Err_Handler
    'Purpose:
    Dim strCaption As String

    '1st choice: Assign the caption of the attached label.
    strCaption = ctl.Controls(0).Caption
    
    '2nd choice: Read the caption from the label over the column in a continuous form.
    If strCaption = vbNullString Then
        strCaption = CaptionFromHeader(frm, ctl)
    End If
    
    'Strip the trailing semicolon.
    If Right$(strCaption, 1&) = ":" Then
        strCaption = Left$(strCaption, Len(strCaption) - 1&)
    End If
    'Strip the ampersand hotkey.
    If InStr(strCaption, "&") > 0& Then
        strCaption = Replace(strCaption, "&&", Chr$(31))
        strCaption = Replace(strCaption, "&", vbNullString)
        strCaption = Replace(strCaption, Chr$(31), "&")
    End If
    '3rd choice: Use the control name.
    If strCaption = vbNullString Then
        strCaption = ctl.Name
    End If
    Caption4Control = strCaption
Exit_Handler:
    Exit Function

Err_Handler:
    Select Case Err.Number
    Case 2467&
        Resume Next
    Case Else
        MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Caption4Control()"
        Resume Exit_Handler
    End Select
End Function

Private Function CaptionFromHeader(frm As Form, ctl As control) As String
On Error GoTo Err_Handler
    'Purpose:   Look for a label in the column header, directly over the control, in continuous form view.
    'Return:    Caption of the label if found.
    Dim ctlHeader As control    'controls in the header of the form.
    Const icRadius = 120        'one twelveth of an inch, in twips.
    
    'If we are in Form view, and it's a Continuous Form,
    '   and there is a label in the Form Header directly above the column, return its Caption.
    If (frm.CurrentView = 1) And (frm.DefaultView = 1) Then
        For Each ctlHeader In frm.Section(acHeader).Controls
            If ctlHeader.ControlType = acLabel Then
                If (ctlHeader.Left > ctl.Left - icRadius) And (ctlHeader.Left < ctl.Left + icRadius) Then
                    CaptionFromHeader = ctlHeader.Caption
                End If
            End If
        Next
    End If
Exit_Handler:
    Set ctlHeader = Nothing
    Exit Function

Err_Handler:
    If Err.Number <> 2462& Then     'No such Section.
        Call LogError(Err.Number, Err.Description, conMod & ".CaptionFromHeader")
    End If
    Resume Exit_Handler
End Function

Private Function HasUnboundControls(frm As Form, ParamArray avarControlNames()) As Boolean
On Error GoTo Err_Handler
    'Purpose:   Return true if all the controls named in the array are present on the form, and are unbound.
    Dim lngI As Long
    Dim bCancel As Boolean
    
    If UBound(avarControlNames) > 0& Then
        'Loop through the named controls on the form.
        For lngI = LBound(avarControlNames) To UBound(avarControlNames)
            If frm.Controls(avarControlNames(lngI)).ControlSource <> vbNullString Then
                bCancel = True
                Exit For
            End If
        Next
        'If we did not drop to the error handler, the form has the named controls.
        HasUnboundControls = Not bCancel
    End If
Exit_Handler:
    Exit Function

Err_Handler:
    Resume Exit_Handler
End Function

Private Function MaxParentNumber(frm As Form) As Long
On Error GoTo Err_Handler
    'Purpose:   Return the PageIndex of the tab page that the control is on.
    'Return:    -1 if setting directly on the form, else the PageIndex of the last page of the tab control.
    'Note:      PageIndex is zero based, so subtract 1 from the count of pages.
    Dim ctl As control          'Each control on the form.
    Dim lngReturn As Long
    
    lngReturn = mlngcOnTheForm      'Initialize to no tab control.
    For Each ctl In frm.Controls
        If ctl.ControlType = acTabCtl Then
            lngReturn = ctl.Pages.Count - 1
            Exit For                    'A form can have only one tab control.
        End If
    Next
    
    MaxParentNumber = lngReturn
    
Exit_Handler:
    Exit Function

Err_Handler:
    Call LogError(Err.Number, Err.Description, conMod & ".MaxParentNumber")
    Resume Exit_Handler
End Function

Private Function ParentNumber(ctl As control) As Integer
On Error Resume Next
    'Purpose:   Return the PageIndex of the tab page that the control is on.
    'Return:    -1 if setting directly on the form, else the page of the tab control.
    'Note:      This works for text boxes and combos, not for labels or controls in an option group.
    Dim iReturn As Integer
    
    iReturn = ctl.Parent.PageIndex
    If Err.Number <> 0& Then
        iReturn = mlngcOnTheForm
    End If
    ParentNumber = iReturn
End Function

Private Function ShowHideControl(frm As Form, strControlName As String, bShow As Boolean) As Boolean
On Error Resume Next
    'Purpose:   Show or hide a control on the form, without error message.
    'Return:    True if the contorl's Visible property was set successfully.
    'Arguments: frm            = a reference to the form where the control is expected.
    '           strControlName = the name of the control to show or hide.
    '           bShow          = True to make visible; False to make invisible.
    'Note:      This is a separate routine, since hiding a non-existant control will error.
    frm.Controls(strControlName).Visible = bShow
    ShowHideControl = (Err.Number = 0&)
End Function

Private Function GetFilterField(ctl As control) As String
On Error GoTo Err_Handler
    'Purpose:   Determine the field name to use when filtering on this control.
    'Return:    The field name the control is bound to, except for combos.
    '               In Access 2002 and later, we return the syntax Access uses for filtering these controls.
    'Argument:  The control we are trying to filter.
    'Note:      We don't use the Recordset of the combo, because:
    '               a) it's not supported earlier than Access 2002, and
    '               b) it's often not loaded at this point.
    '               Instead, we OpenRecordset to get the source field name,
    '               which works even if the field is aliased in the RowSource.
    '               Opening for append only is quicker, as it loads no existing records.
    Dim rs As DAO.Recordset     'To get information about the combo's RowSource.
    Dim iColumn As Integer      'The first visible column of the combo (zero-based.)
    Dim strField As String      'Return value: the field name to use for the filter string.
    Dim bCancel As Boolean      'Flag to not filter on this control.
    
    If ctl.ControlType = acComboBox Then
        iColumn = FirstVisibleColumn(ctl)
        If iColumn = ctl.BoundColumn - 1 Then
            'The bound column is the first visible column: filter on the control source field.
            strField = "[" & ctl.ControlSource & "]"
        Else
            'In Access 2002 and later, we can use the lookup syntax Access uses, if the source is a Table/Query.
            If Int(Val(SysCmd(acSysCmdAccessVer))) >= 10 Then
                If ctl.RowSourceType = "Table/Query" Then
                    Set rs = DBEngine(0)(0).OpenRecordset(ctl.RowSource, dbOpenDynaset, dbAppendOnly)
                    With rs.Fields(iColumn)
                        strField = "[Lookup_" & ctl.Name & "].[" & .SourceField & "]"
                    End With
                    rs.Close
                Else
                    bCancel = True  'Hidden bound column not supported if RowSourceType is Value List or call-back function.
                End If
            Else
                bCancel = True      'Hidden bound column not supported for versions earlier than Access 2002.
            End If
        End If
    Else
        'Not a combo: filter on the control source field.
        strField = "[" & ctl.ControlSource & "]"
    End If
    If strField <> vbNullString Then
        GetFilterField = strField
    ElseIf Not bCancel Then
        GetFilterField = "[" & ctl.ControlSource & "]"
    End If
    Set rs = Nothing

Exit_Handler:
    Exit Function

Err_Handler:
    Call LogError(Err.Number, Err.Description, conMod & ".GetFilterField")
    Resume Exit_Handler
End Function

Private Function FirstVisibleColumn(cbo As ComboBox) As Integer
On Error GoTo Err_Handler
    'Purpose:   Return the column number of the first visible column in a combo.
    'Return:    Column number. ZERO-BASED!
    'Argument:  The combo to examine.
    'Note:      Also returns zero on error.
    Dim i As Integer            'Loop controller.
    Dim varArray As Variant     'Array of the combo's ColumnWidths values.
    Dim iResult As Integer      'Colum number to return.
    Dim bFound As Boolean       'Flag that we found a value to return.
    
    If cbo.ColumnWidths = vbNullString Then
        'If no column widths are specified, the first column is visible.
        iResult = 0
        bFound = True
    Else
        'Parse the ColumnWidths string into an array, and find the first non-zero value.
        varArray = Split(cbo.ColumnWidths, mstrcSep)
        For i = LBound(varArray) To UBound(varArray)
            If varArray(i) <> 0 Then
                iResult = i
                bFound = True
                Exit For
            End If
        Next
        'If the column widths ran out before all columns were checked, the next column is the first visible one.
        If Not bFound Then
            If i < cbo.ColumnCount Then
                iResult = i
                bFound = True
            End If
        End If
    End If
    FirstVisibleColumn = iResult

Exit_Handler:
    Exit Function

Err_Handler:
    Call LogError(Err.Number, Err.Description, conMod & ".FirstVisibleColumn")
    Resume Exit_Handler
End Function

'------------------------------------------------------------------------------------------------
'You may prefer to replace this with a true error logger. See http://allenbrowne.com/ser-23a.html
Private Function LogError(ByVal lngErrNumber As Long, ByVal strErrDescription As String, _
    strCallingProc As String, Optional vParameters, Optional bShowUser As Boolean = True) As Boolean
On Error GoTo Err_LogError
    ' Purpose: Generic error handler.
    ' Arguments: lngErrNumber - value of Err.Number
    ' strErrDescription - value of Err.Description
    ' strCallingProc - name of sub|function that generated the error.
    ' vParameters - optional string: List of parameters to record.
    ' bShowUser - optional boolean: If False, suppresses display.
    ' Author: Allen Browne, allen@allenbrowne.com

    Dim strMsg As String      ' String for display in MsgBox

    Select Case lngErrNumber
    Case 0
        Debug.Print strCallingProc & " called error 0."
    Case 2501                ' Cancelled
        'Do nothing.
    Case 3314, 2101, 2115    ' Can't save.
        If bShowUser Then
            strMsg = "Record cannot be saved at this time." & vbCrLf & _"Complete the entry, or press <Esc> to undo."
            MsgBox strMsg, vbExclamation, strCallingProc
        End If
    Case Else
        If bShowUser Then
            strMsg = "Error " & lngErrNumber & ": " & strErrDescription
            MsgBox strMsg, vbExclamation, strCallingProc
        End If
        LogError = True
    End Select

Exit_LogError:
    Exit Function

Err_LogError:
    strMsg = "An unexpected situation arose in your program." & vbCrLf & _"Please write down the following details:" & vbCrLf & vbCrLf & _"Calling Proc: " & strCallingProc & vbCrLf & _"Error Number " & lngErrNumber & vbCrLf & strErrDescription & vbCrLf & vbCrLf & _"Unable to record because Error " & Err.Number & vbCrLf & Err.Description
    MsgBox strMsg, vbCritical, "LogError()"
    Resume Exit_LogError
End Function


Karim Vaziri Regards,



Report print and potentially aggregate

$
0
0

Hi,

I have a set of reports I would like to run at the end of a Case. Does anyone have any suggestions as to be best way to implement producing them? Reports are something like:

Case notes. (tblCaseNotes)

Case Events (tblCaseEvents)

Case Details (tblDetails)

Print all three, and potnetially maybe some way to join them all into one (if possible)?

Relationships

Customer 1:M Case

Case 1:M Events

Case 1:M CaseNotes

I have read something about sub reports, but not quite sure how to use / implement.

Seeking some views, all appreciated.

Thanks

John



JG


MS Access SQL Query - Manipulate

$
0
0

Hi Folks -

I have the following SQL query that returns a set of data and ensure the Alias column is >= 40 characters.

SELECT 'ZRND' AS [Order Type], ChangeExistingPFP.[PFP Code] AS IO, Left(ChangeExistingPFP.N_Alias,40) AS Description
FROM ChangeExistingPFP
WHERE ChangeExistingPFP.N_Alias IS NOT NULL;

However, there are times when it cuts up chracters and leaves an open "(" without a closed ")".

Like such:

Kabuki - Ph 1b/2a Adult POC Study (TAK-4
Rett - POC Study (Adolescent & Adults) (

Is there a way to add to the query to detect those situations and just add an ")" to the result where found? For the second instance, just remove the open "(" since not comes after.

Thank you!

recordset locking

$
0
0

I am having conflicts with a specific table in an MSAccess database due to multiple users.    I wish to change the locking to Pessimistic for that table.    Is there a way to do this programmatically?   I program in vb.net.

If not in by VS2017 program, how do I set the properties of that table to 2 or pessimistic in the Access database?

"Mysterious" values in the multi value field - Why

$
0
0

Hi

I have a table with one multi value field. For some reason two values sometimes i stored, a name of a person and a number. The name is always the same (there is only one person to pick from a list) The number is not random, but nearly.

I cant understand why. Please see this copy of the table content:

<tfoot></tfoot>
Table DH
Personal
Marten Schmidt; 14
Marten Schmidt; 27
Marten Schmidt
Marten Schmidt
18
Marten Schmidt
Marten Schmidt
Marten Schmidt
35
Marten Schmidt; 35
Marten Schmidt
Marten Schmidt
Marten Schmidt
Marten Schmidt
Marten Schmidt; 35
Marten Schmidt; 27
Marten Schmidt; 27
Marten Schmidt; 35
Marten Schmidt; 28
Marten Schmidt; 27



Cheers // Peter Forss Stockholm

Stop the "do you want to save changes to design of the form message" - Access 2010 ONLY

$
0
0

This only applied to Access 2010 , and, AFAIK, only applies when using DataSheets as subforms of Navigation Controls.

Steps to reproduce the problem:

1. Create a datasheet view based on a table

2. Add the dataview as a tab on a navigation form (one that has other tabs showing other forms)

3. Display the navigation form and goto to the datsheet

4. Sort or filter the data sheet

5. Got to a different tab in the Nav control

6. You get a message saying; "do you want to save changes to the design..."

 

Any suggestions on how to get rid of it?

Replies that would not be helpful include:
- "Don't use navigation controls, they are new and we never needed them in Access 97"
- "Don't use a datasheet - use a continuous form"
- "Set the form to 'don't allow layout view'" (this would prevent the users from sorting and filter - so what's the point)

 

...I also can't set warnings off on opening the datasheet and turn it back on on closing it because the form has links to various other forms (though, now that I think about it I may just turn off warnings all together though I'd rather not).

 

Any other solutions you guys can come up with would be great!

Thanks,
CList

 

 

Web Servicd 401 error

$
0
0

I have created a dll that will access a web service. I have registered this on my machine and have it working properly. When moving to client machine I got it registered but it returns a 401 error. Any ideas on what could be going wrong?

Dale

Viewing all 14673 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>