Expected user defined type not project как исправить access

  • Remove From My Forums
  • Question

  • Hey there! I’m trying to code a login form for my database but I’ve ran into some problems.. This is part of my GCE O Level coursework, I’ve spent a few hours trying to look for the solution to this problem but they don’t really work. :/

    It says Expected user-defined type, not project  and Dim db As Database is highlighted.. 

    Option Compare Database
    Dim db As Database
    Dim rs As Recordset
    Dim bFoundMatch As Boolean

    Private Sub btnLogin_Click()

        Set db = CurrentDb

        Set rs = db.OpenRecordset(“Login”)

        
        bFoundMatch = False

        
        If rs.RecordCount > 0 Then

            rs.MoveFirst

            
            
            Do While rs.EOF = False
                If rs![Username] = Form_Login.txtUsername.Value And rs![Password] = Form_Login.txtPassword.Value Then
                    bFoundMatch = True

                    
                    Exit Do
                Else
                    rs.MoveNext
                End If
            Loop
        End If

        
        If bFoundMatch = True Then
            DoCmd.Close acForm, Me.Name
            DoCmd.OpenForm “Switchboard”
        Else
            MsgBox “Incorrect username or password entered!”, vbOKOnly + vbCritical, “Incorrect credentials!”
        End If

        
        rs.Close
    End Sub

    • Edited by

      Thursday, February 9, 2012 2:04 PM

Answers

  • In the Visual Basic Editor, you’ll probably see an item Database Properties… in the Tools menu.

    Select this item, change the Project Name to something different than Database (for example My Database), then click OK.

    The conflict should now be gone.


    Regards, Hans Vogelaar

    • Proposed as answer by
      Bruce Song
      Tuesday, February 14, 2012 7:46 AM
    • Marked as answer by
      Bruce Song
      Thursday, February 23, 2012 10:02 AM

  • Hi Jia Jian,

    I also encountered the problem before, you can also define db varible like this:

    Dim db As DAO.Database

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by
      Bruce Song
      Thursday, February 23, 2012 10:03 AM

1 / 1 / 0

Регистрация: 16.06.2013

Сообщений: 46

1

17.04.2016, 19:06. Показов 6849. Ответов 5


Студворк — интернет-сервис помощи студентам

Создал форму добавления/удаления полей в таблицы. При добавлении нового поля вылазит ошибка

Миниатюры

Не могу понять как исправить ошибку (Expected user-defined type, not project)
 



0



шапоклякистка 8-го дня

3675 / 2235 / 391

Регистрация: 26.06.2015

Сообщений: 4,647

Записей в блоге: 1

17.04.2016, 19:19

2

Библиотеку DAO подключить надо.



2



Эксперт MS Access

26783 / 14462 / 3192

Регистрация: 28.04.2012

Сообщений: 15,782

17.04.2016, 19:26

3

БД при создании называлось Database, имя сохранилось и конфликтует с типом Database. Но если прямо указать родительский объект, т.е. написать As DAO.Database, то конфликта не будет



3



shanemac51

Модератор

Эксперт MS Access

11376 / 4687 / 756

Регистрация: 07.08.2010

Сообщений: 13,594

Записей в блоге: 4

17.04.2016, 19:28

4

да и явная ссылка не помешает

Visual Basic
1
2
Dim dbs As dao.Database, tdf As dao.TableDef, fld As dao.Field
Set dbs = CurrentDb



3



1 / 1 / 0

Регистрация: 16.06.2013

Сообщений: 46

17.04.2016, 20:37

 [ТС]

5

Всем спасибо !))))



1



Эксперт MS Access

7330 / 4471 / 288

Регистрация: 12.08.2011

Сообщений: 13,534

18.04.2016, 07:49

6

Цитата
Сообщение от DeadDance
Посмотреть сообщение

Всем спасибо !))))

Зачем обманываете? Где спасибо?

Добавлено через 2 часа 25 минут
Хм, промазал



3



I’ve looked through several pages on SF on this error. This is the first time I’ve tried to add records to Access via VBA. Here is my code:

Option Compare Database

Public Sub Retrieve_SOPS()
' Retrieve SOP files
    'Record starting timer - BEGIN
    Dim StartTime As Double
    StartTime = Timer

    'Set network folder path
    Const FolderPath As String = "\JACKSONVILLE-DCCommonSOP's for JVSOPs Final"

    'Instantiate FSO
    Dim oFSO As Object
    Dim oFolder As Object
    Dim oFiles As Object
    Dim oFile As Object
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oFolder = oFSO.GetFolder(FolderPath)
    Set oFiles = oFolder.Files

    'Instantiate DAO
    Dim db As DAO
    Dim rs As DAO.Recordset
    Set db = CurrentDb
    Set rs = db.OpenRecordset("tblSOP", dbOpenDynaset)

    Dim v As Variant

    'Loop through each file in FSO
    For Each oFile In oFiles
        'Remove temporary/hidden files
        If (oFile.Attributes And 2) <> 2 Then
            'Split filename
            v = Split(oFile.Name, "-")

            ' Instantiate Necessary Variables
            Dim file_path As String
            Dim file_id As Integer
            Dim file_title As String
            Dim lang_code As String
            Dim creation_date As String

            file_path = oFile.Path
            file_id = v(2)
            file_title = v(4)
            lang_code = v(5)
            'If dimension in array exists; Remove file extension
            If UBound(v) >= 6 Then
                creation_date = v(6)
            End If

            With rs
                .AddNew

                .Fields("file_path").Value = file_path
                .Fields("file_id").Value = file_id
                .Fields("file_title").Value = file_title
                .Fields("lang_code").Value = lang_code
                If UBound(v) >= 6 Then
                    .Fields("creation_date").Value = creation_date
                End If
            End With
        End If

        'Stop For Loop (TEMP)
        Exit Sub
    Next oFile
End Sub

Then I get this error: “Compile error: Expected user-defined type, not project”

I’m reading “Microsoft Access 2019 Bible” By Wiley.

I have read the following links but still can’t understand what I am doing wrong:

  1. Compiler Error: User-defined types not defined

  2. ms access compile error: user-defined type not defined

braX's user avatar

braX

11.5k5 gold badges19 silver badges33 bronze badges

asked Oct 30, 2019 at 16:19

mongoose00318's user avatar

1

And you missed the update:

       With rs
            .AddNew
            .Fields("file_path").Value = file_path
            .Fields("file_id").Value = file_id
            .Fields("file_title").Value = file_title
            .Fields("lang_code").Value = lang_code
            If UBound(v) >= 6 Then
                .Fields("creation_date").Value = creation_date
            End If
            .Update
       End With

answered Oct 30, 2019 at 16:31

Gustav's user avatar

GustavGustav

52.9k7 gold badges29 silver badges55 bronze badges

2

Permalink

Cannot retrieve contributors at this time

title keywords f1_keywords ms.prod ms.assetid ms.date ms.localizationpriority

Expected user-defined type, not project

vblr6.chm1035019

vblr6.chm1035019

office

f84f3542-fe4b-6aa1-1d96-5c7423661070

06/08/2017

medium

There is no user-defined type by this name in the current scope, but there is a project by this name. You can define a variable as having user-defined type, but not project type. This error has the following cause and solution:

  • The name of a project is used as a user-defined type. Check the spelling of the name of the user-defined type, and make sure the user-defined type isn’t private to another module.

For additional information, select the item in question and press F1 (in Windows) or HELP (on the Macintosh).

[!includeSupport and feedback]

A couple of comments are in order. First, a simple one.

This statement: Dim sqlStr, insertSQL, arrayVal As String doesn’t do what you think it does. Only arrayVal is actually a string. The other two elements are variants. Correct syntax to make all three of those strings is Dim sqlStr As String, insertSQL As String, arrayVal As String because the “As String” modifiers do not distribute across all three elements. They ONLY apply to the variable that they immediately follow.

I think you have an error in this: TestArray() = Split(fielObjectives, “, “) in that if that was a cut/paste, you have spelled something wrong. AND you did it when filling variables from rs.Fields().

Now, the next comment: It is hard to be sure, but the only other thing that comes to mind is that you should always qualify anything you know to be a structure, such as recordset objects. They can be DAO.recordset or ADO.recordset or some other type of recordset, but they are external to Access in that they are defined in a library, not in Access itself. For me it is a matter of what I think to be “good practice” to ALWAYS qualify objects with where they originate.

The User-Defined Data Type error PROBABLY comes from the TestArray() = Split(fielObjectives, “, “) line because Split doesn’t know what fielObjectives is. You didn’t define that. You defined fieldObjectives in your Dim statement.

Добавить комментарий