Question : imported forms, reports, and table into another db and not working

hello,
in a small database i created - i use this code behind a combo box to add items to list-
now I imported form, reports- table and queries to another database.
When I try to add item to combo box now- i recieve error

dim db as database // in code is highlighted-
a message box appears- (ms visual basic)- compile error: user defined type not defined
and i receive " the text you entered isn't in a list
any ideas of why it is not working-
i attached code
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
Private Sub cboCompany_NotInList(NewData As String, Response As Integer)

'Suppress the default error message.

Response = acDataErrContinue

' Prompt user to verify if they wish to add a new value.

If MsgBox("The company of " & NewData & " is not in list. Add it?", vbYesNo) = vbYes Then

' Set Response argument to indicate that data is being added.

'Open a recordset of the tblCompany Table.

Dim db As Database

Dim rstcboCompany As Recordset

Dim sqltblCompany As String

Set db = CurrentDb()

sqltblCompany = "Select * From tblCompany "

Set rstcboCompany = db.OpenRecordset(sqltblCompany, dbOpenDynaset)

'Add a new Company with the value that is stored in the variable NewData.

rstcboCompany.AddNew

rstcboCompany![CompanyName] = NewData

rstcboCompany.Update

'Inform the combo box that the desired item has been added to the list.

Response = acDataErrAdded

rstcboCompany.Close 'Close the recordset

End If

End Sub

Answer : imported forms, reports, and table into another db and not working

<I imported form, reports- table and queries to another database.>
What format database was the source, and what format was the target?
Access 2003-->Access 2003?
Access 2003-->Access 2007?
Access 2007-->Access 2003?
Access 2007-->Access 2007?

Did you import them into a blank, new database?
Did you run the compact Repair utility before the import in the source DB, ...and then in the target DB, after the import?
Did you compile the code in the target, after the import? (in the VBA Editor click: Debug-->Compile)

Let's also redo some of the code:

'
Private Sub cboCompany_NotInList(NewData As String, Response As Integer)

Dim db As DAO.Database
Dim rstcboCompany As DAO.Recordset
Dim sqltblCompany As String

Set db = CurrentDb()
'Suppress the default error message.
Response = acDataErrContinue

' Prompt user to verify if they wish to add a new value.
    If MsgBox("The company of " & NewData & " is not in list. Add it?", vbYesNo) = vbYes Then
   
        ' Set Response argument to indicate that data is being added.
        'Open a recordset of the tblCompany Table.
        sqltblCompany = "Select * From tblCompany "
   
        Set rstcboCompany = db.OpenRecordset(sqltblCompany, dbOpenDynaset)
       
        'Add a new Company with the value that is stored in the variable NewData.
        rstcboCompany.AddNew
       
        rstcboCompany![CompanyName] = NewData
       
        rstcboCompany.Update
       
        'Inform the combo box that the desired item has been added to the list.
       
        Response = acDataErrAdded
   
    End If
   
'Cleanup
rstcboCompany.Close
Set rstcboCompany = Nothing
db.Close
Set db = Nothing

End Sub
'


Now insert this, Compile the code (in the VBA Editor click: Debug-->Compile) and give it a whirl...

Let us know the results.

;-)

JeffCoachman
Random Solutions  
 
programming4us programming4us