Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error in concatenation

Status
Not open for further replies.

samotek

Technical User
May 9, 2005
197
0
0
BG
I cannot concatenate properly the line
Set BackDB = OpenDatabase(DBName,pwd=" & StrPassword)
which is wrong and gives me errors.Can you help ?

Public Function ImportAllTables(DBName, strPassword As String)
strPassword = " pin"
Dim FrontDB As DAO.Database, BackDB As DAO.Database, Tbl As TableDef
Set FrontDB = CurrentDb
Set BackDB = OpenDatabase(DBName,pwd=" & StrPassword)
For Each Tbl In BackDB.TableDefs
If Tbl.Attributes = 0 Then
DoCmd.TransferDatabase acImport, "Microsoft Access", BackDB.Name, acTable, Tbl.Name, Tbl.Name
End If
Next
BackDB.Close
FrontDB.Close
End Function
 
samotek

When you need a variable value in a Sub/Function, you either pass it (byVal or byRef) as a argument of the Sub/Function or if the scope of the variable allows is to be "live" when the Sub/Function run, or it is a value defined inside the Sub/Function. As you declared your Function, strPassword is a non-optional argument! So when you call the Function you have to pass the values for DBName & strPassword.

For your case

Set BackDB = OpenDatabase(DBName, StrPassword)

PLEASE dont open new threads for associated questions like thread181-1426855, thread181-1426855, thread705-1426701, thread705-1426328

 
I try to call the function by :
ImportAllTables( "C:\be\be.mdb","secret")
but i get the message compile error

Please help me
here is my function again :

Public Function ImportAllTables(DBName, StrPassword As String)
Dim FrontDB As DAO.Database, BackDB As DAO.Database, Tbl As TableDef
Set FrontDB = CurrentDb
',Set BackDB = wsp.OpenDatabase(DBName, False, False, ";PWD=" & StrPassword)
Set BackDB = OpenDatabase(DBName, , , ";PWD=" & StrPassword)

For Each Tbl In BackDB.TableDefs
If Tbl.Attributes = 0 Then
DoCmd.TransferDatabase acImport, "Microsoft Access", BackDB.Name, acTable, Tbl.Name, Tbl.Name
End If
Next
BackDB.Close
FrontDB.Close
End Function

 
Actually my error occurs in the onlick event in the lines :
ImportAllTables( "C:\be\be.mdb","secret")
the figures are red at the beginning . showing that i am missing something.The database is secured with the word secret, but i havent declared it in the code ?
 

Functions are decleared to be of some type, like variables. This is because a function is supposed to return something.

ie
Public myFunctionA (strParam as String, lFAFGW As Long etc) As String
Public myFunctionB (strParam as String, lFAywW As Currency etc) As Long

The default is Boolean
If you want to use the function you have to assign the return value to a variable of the same type.

Dim myVariableA As String
myVariableA = myFunctionA ("LALALA", 654)
Dim myVariableB As Long
myVariableB = myFunctionB ("LALALA", 654.4406)
------------------------------------------------
Your case
Code:
Sub btnImport_Click() 
' A button's click event (placed on form) named as btnImport
Dim a As Boolean
a=ImportAllTables
msgbox a
End Sub

Code:
Public Function ImportAllTables(DBName, StrPassword As String) As Boolean
Dim BackDB As DAO.Database
Dim Tbl As DAO.TableDef

Set BackDB = OpenDatabase(DBName, , , StrPassword)

For Each Tbl In BackDB.TableDefs
   If Tbl.Attributes = 0 Then
      DoCmd.TransferDatabase acImport, "Microsoft Access", BackDB.Name, acTable, Tbl.Name, Tbl.Name
   End If
Next

BackDB.Close

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top