Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Posts
    17

    Unanswered: User-defined type not defined

    HiHi~

    I am working on MS Access & VB for my school project... now I am having trouble to create a database object~~

    When I use Dim Db As Database, it says user-defined type not defined.

    What does that mean??

    My Code
    Code:
    Private Sub Check44_Click()
    
        Dim Db As Database
        Dim strSQL As String
    
        strSQL = "SELECT * FROM profile WHERE user = 1"
        
        MsgBox ("Test")
        
    End Sub
    I am using MS Access 2002~ Please Help~

  2. #2
    Join Date
    Mar 2004
    Location
    Adelaide, Australia
    Posts
    32

    Re: User-defined type not defined

    Originally posted by YUPAPA
    HiHi~

    I am working on MS Access & VB for my school project... now I am having trouble to create a database object~~

    When I use Dim Db As Database, it says user-defined type not defined.

    What does that mean??

    My Code
    Code:
    Private Sub Check44_Click()
    
        Dim Db As Database
        Dim strSQL As String
    
        strSQL = "SELECT * FROM profile WHERE user = 1"
        
        MsgBox ("Test")
        
    End Sub
    I am using MS Access 2002~ Please Help~
    Your code is a little bit incomplete. Not exactly sure what you are trying to do here. You have associated this code to the CLICK event of a checkbox. Why?

    VB has interpreted "Database" in "Dim Db as Database" as a User-Defined Type, and as you haven't defined it, it throws up an error.

  3. #3
    Join Date
    Mar 2004
    Posts
    17
    What I am trying to do is that when a user checks the box, it will run the SQL statement. The SQL statement is to select the address from a table, then set it to a textbox's value.

    Bascially the checkbox is to ask the user if he wants to fill out the address with the one stored in the 'profile' table.

    I understand that the code is incomplete. What I am trying to do is to solve the Dim Db As Database problem first and then perform Db.Execute strSQL.

    Sorry I am VERY new to VB & Access

  4. #4
    Join Date
    Mar 2004
    Location
    Adelaide, Australia
    Posts
    32

    Wink

    Originally posted by YUPAPA
    What I am trying to do is that when a user checks the box, it will run the SQL statement. The SQL statement is to select the address from a table, then set it to a textbox's value.

    Bascially the checkbox is to ask the user if he wants to fill out the address with the one stored in the 'profile' table.

    I understand that the code is incomplete. What I am trying to do is to solve the Dim Db As Database problem first and then perform Db.Execute strSQL.

    Sorry I am VERY new to VB & Access
    No need to apologise, this is a place for all to learn, newbies and oldies.

    I would suggest that you use ADO.

    You could try this:

    [code]
    Private Sub Check44_Click()

    Dim myDb as ADODB.Connection
    Dim myRS as ADODB.Recordset
    Dim sSQL as String

    Set myDb = CurrentProject.Connection
    Set myRS = New ADODB.Recordset
    sSQL = "SELECT * FROM Profile WHERE myFieldName = " & Me.myControl
    myRS.Open sSQL, myDb
    ' move table fields to form controls
    Me.txtStreetNo = myRS!StreetNo
    Me.txtStreetName = myRS!StreetName
    ' etc.
    myRS.Close
    myDb.Close

    Set myRS = Nothing
    Set myDb = Nothing

    End Sub
    [\code]

    Difficult to give you full example of code without table, field, form and control names, but have a look at the above and see how you go.

    I only have Access2000 so sending me a copy of your database, unless you can save it as Access2000 version.

    HTH.

  5. #5
    Join Date
    Mar 2004
    Posts
    17

    Talking

    THANK YOU THANK YOU~
    It works~

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •