J
Joe
Hi
There are three command buttons and a combo box in a form.
Here is the code in the first button:
On Error GoTo TrataErro
Dim sql As String
sql = "ALTER TABLE Clientes ADD COLUMN Celular Text (38)"
DoCmd.RunSQL sql
MsgBox "The field Celular was created!"
Exit Sub
TrataErro:
MsgBox "The Field Celular already exists!"
Here is the code in the second button:
On Error GoTo TrataErro
Dim sql As String
sql = "ALTER TABLE Clientes DROP COLUMN Celular"
DoCmd.RunSQL sql
MsgBox "The field Celular was deleted!"
Exit Sub
TrataErro:
MsgBox "The field Celular doesn't exist!", , TIT
By clicking the buttons, the code works exactly as expected. The field is
created and then deleted.
Here is the code in the third button, which goal is to program the combo box
cmbClientes:
Dim sql As String
sql = "SELECT DISTINCT Estado FROM Clientes"
cmbClientes.RowSource = sql
cmbClientes.SetFocus
cmbClientes.Dropdown
If I press the first Button, the code doesn't work. The message in the error
handling is shown.
If I disable the error handling, the following message is shown: The
database engine could not lock the table Clientes, it is already in use.
I don't understand where the error is, nor how to solve it.
Please, could you help me?
Thanks
Joe
There are three command buttons and a combo box in a form.
Here is the code in the first button:
On Error GoTo TrataErro
Dim sql As String
sql = "ALTER TABLE Clientes ADD COLUMN Celular Text (38)"
DoCmd.RunSQL sql
MsgBox "The field Celular was created!"
Exit Sub
TrataErro:
MsgBox "The Field Celular already exists!"
Here is the code in the second button:
On Error GoTo TrataErro
Dim sql As String
sql = "ALTER TABLE Clientes DROP COLUMN Celular"
DoCmd.RunSQL sql
MsgBox "The field Celular was deleted!"
Exit Sub
TrataErro:
MsgBox "The field Celular doesn't exist!", , TIT
By clicking the buttons, the code works exactly as expected. The field is
created and then deleted.
Here is the code in the third button, which goal is to program the combo box
cmbClientes:
Dim sql As String
sql = "SELECT DISTINCT Estado FROM Clientes"
cmbClientes.RowSource = sql
cmbClientes.SetFocus
cmbClientes.Dropdown
If I press the first Button, the code doesn't work. The message in the error
handling is shown.
If I disable the error handling, the following message is shown: The
database engine could not lock the table Clientes, it is already in use.
I don't understand where the error is, nor how to solve it.
Please, could you help me?
Thanks
Joe