1

I am just trying to play around with Access and SQL and I have created a simple table named Employees with one column named lastName.

I have created a simple form called Employees that has one textbox named lastName and one button named UpdateLastName.

My code so far is:

Private Sub buttonUpdateLastName_Click()
   DoCmd.RunSQL "insert into employees values('" & Me.lastName & "');"
End Sub

I do not get any compilation errors, but whenever I click the UpdateLastName button, I just get blank space inserted into my Employees table.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
dcfjoe
  • 61
  • 1
  • 3
  • 1
    Try adding a breakpoint to your code and examining the value of `Me.lastName`. If the SQL is running as expected (which it sounds like it is), then `lastName` must be an empty string (or spaces). – Martin Jun 09 '15 at 15:48

2 Answers2

0

What I have used in the past in C# is exactly the code below.

    string conectionstring = "datasource=localhost;port=3306;username=root;password=!35HC!";
                MySqlConnection ConnectionDB = new MySqlConnection(conectionstring);
                MySqlCommand command = ConnectionDB.CreateCommand();
                command.CommandText = "INSERT INTO geodb.users (Username,Password,Name,Surname,Sxoleio,Kathigitis) VALUES ('" + this.TextBox6.Text + "', '" + this.TextBox7.Text + "', '" + this.TextBox3.Text + "', '" + this.TextBox4.Text + "', '" + this.TextBox5.Text + "', '" + kathigitis + "');";
                ConnectionDB.Open();
                command.ExecuteNonQuery();
                ConnectionDB.Close();
Theojim
  • 103
  • 3
  • 8
0

Thank You Martin Parkin for the suggestion to check my textbox to see if it was in fact empty thus sending empty space to my table.

I deleted the premade for me textbox and put a brand new unbound textbox in my form and changed its name. This new textbox is working fine now and is doing what I want it to do.

I guess the premade textbox had some event code already written for it that was making it send whitespace to my table.

dcfjoe
  • 61
  • 1
  • 3