1 Replies - 324 Views - Last Post: 12 August 2012 - 03:36 AM Rate Topic: -----

#1 Ahmed Faid  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 12-August 12

question about file handling

Posted 12 August 2012 - 02:57 AM

i created a program which can create a database and it works very good,i made it when the user create a new database with a name which is already in use, a msgbox prompt that he can overwrite it,
the problem is that i want to make the database name variable like 'x' which is the name of the new database,when the user choose to overwrite the program should use the app.path and the file name which is \'x'.mdb

h:
    Dim x As String
    x = InputBox("Enter the database name", "Database Name", "new database")
    
    If x = "" Then
        MsgBox "Wrong database Name"
        Exit Sub
    End If
   
    
On Error GoTo s
    
    Set db = CreateDatabase(x, dbLangGeneral)
    db.Execute ("create table RegForm (RDate date,RName text (30),RAddrs text (100),RTel text (25),REmail text (50),RDevc text (20),RModel text (20),RSno text (20),ID text (10));")
    db.Close
    MsgBox "database has been created"
    Exit Sub
    
s:
    Dim e As String
    e = MsgBox("Database name is used,Do you want to overwrite it?", vbYesNoCancel + vbCritical, "Error")
    
    If e = vbYes Then

                                      'The problem is here*************
'*****************************
        Kill App.Path & "\+x+.mdb"
'*****************************
        Set db = CreateDatabase(x, dbLangGeneral)
        db.Execute ("create table RegForm (RDate date,RName text (30),RAddrs text (100),RTel text (25),REmail text (50),RDevc text (20),RModel text (20),RSno text (20),ID text (10));")
        db.Close
        MsgBox "database has been created"
        Exit Sub
    End If
  
    If e = vbNo Then
        GoTo h
    End If
    
End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: question about file handling

#2 Ahmed Faid  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 12-August 12

Re: question about file handling

Posted 12 August 2012 - 03:36 AM

i solved the problem , i'm new in vb6 , but i just tried to use my brain :D
the code is:
h:
    Dim x As String
    x = InputBox("Enter the database name", "Database Name", "new database")
    
    If x = "" Then
        MsgBox "Wrong database Name"
        Exit Sub
    End If
   
    
On Error GoTo s
    
    Set db = CreateDatabase(x, dbLangGeneral)
    db.Execute ("create table RegForm (RDate date,RName text (30),RAddrs text (100),RTel text (25),REmail text (50),RDevc text (20),RModel text (20),RSno text (20),ID text (10));")
    db.Close
    MsgBox "database has been created"
    Exit Sub
    
s:
    Dim e As String
    e = MsgBox("Database name is used,Do you want to overwrite it?", vbYesNoCancel + vbCritical, "Error")

    If e = vbYes Then
        'the problem was here*************
       
         Kill App.Path + "\" + x + ".mdb"

        Set db = CreateDatabase(x, dbLangGeneral)
        db.Execute ("create table RegForm (RDate date,RName text (30),RAddrs text (100),RTel text (25),REmail text (50),RDevc text (20),RModel text (20),RSno text (20),ID text (10));")
        db.Close
        MsgBox "database has been created"
        Exit Sub
    End If
    
    If e = vbNo Then
        GoTo h
    End If



Was This Post Helpful? 1
  • +
  • -

Page 1 of 1