473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How do I INSERT INTO a table a variable value

14
Here is my code. I am trying to INSERT INTO "Master_Table" field "Edited_By" the variable value of "Editor"

"Editor" is the User Name of the person logged onto that computer

Code

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4.       Declare Function WNetGetUser Lib "mpr.dll" _
  5.       Alias "WNetGetUserA" (ByVal lpName As String, _
  6.       ByVal Editor As String, lpnLength As Long) As Long
  7.  
  8.       Const NoError = 0 
  9.  
  10. Sub GetUserName()
  11.  
  12.      Const lpnLength As Integer = 255
  13.  
  14.       Dim status As Integer
  15.       Dim lpName, Editor As String
  16.  
  17.        Editor = Space$(lpnLength + 1) 
  18.        status = WNetGetUser(lpName, Editor, lpnLength)
  19.  
  20.       If status = NoError Then
  21.          Editor = Left$(Editor, InStr(Editor, Chr(0)) -1)
  22.  
  23.          CurrentDb.Execute "INSERT INTO Master_Table " &_
  24.               "(Edited_By) " & _
  25.                  "VALUES ('" & Editor & "');"
  26.  
  27.       Else
  28.  
  29.          MsgBox "Unable to get the name."
  30.          End
  31.  
  32.       End If
  33.  
  34. End Sub
Sep 15 '10 #1
5 1949
NeoPa
32,556 Expert Mod 16PB
And? You haven't left us with a question. Nor have you explained what happens and when with the code.

I'm sure we can help you, but we need somewhere to start.
Sep 15 '10 #2
JonHuff
14
The question was "How do I INSERT INTO a table a variable value". My code is not working.

the code provided showed I was trying to INSERT INTO table "Master_Table" field "Edited_By" the value of the variable "Editor". I dont know how else to say it.
Sep 15 '10 #3
NeoPa
32,556 Expert Mod 16PB
Well, the obvious place to start would be with my prompting question.

What line does the code fail on?
What error message do you get if any?
If it fails on line #23 as I suspect then what is the actual SQL string passed to the execute command?
Sep 15 '10 #4
pod
298 100+
What is this lonely "End" doing on line #30?
Sep 15 '10 #5
JonHuff
14
I figured it out. I was trying to execute the code while my form was open. The form is based off the table I was trying to write to (DUH !!!). I changed it to write to a new test table - it works fine now. Thanks for looking anyways.
Sep 15 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mike Combe | last post by:
Hello All, Given..... <!--#include file="htm1.asp" --> Any ideas how to make the 'htm1.asp' a variable name? Say at one time we want to use 'htm1.asp' and another
4
by: keerthana_m_2003 | last post by:
Hello: is it possible to insert the value of some JavaScript variable in the body of HTML (for example the text on button, or at any part of the HTML text part). Please tell me how to do this. ...
2
by: fatjoez | last post by:
Hi there. I'm trying to create a Trigger for on insert, which will be triggered upon any attempted insert into a database table item. Basically want it to say, if the attempted insert value for...
2
by: duancg | last post by:
Hi, I wonder if someone could help since I wasn't able to find the answer through search. I have a simple .aspx page that shows data from a database table, as a table in UI. Now the data uses...
0
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I want to display a progress bar on my web page. I have this code for progress bar in javascript in my web page. I have a button on the web page, if someone clicks that button...
2
chathura86
by: chathura86 | last post by:
hi, i'm retrieving a string from a database and i want to insert a value which comes from another variable into that. for a example String in the data base: "Dear %name%, Thank you" and i...
2
by: yeap | last post by:
Hi All, I can't insert java variable into ms access database. I'm using odbc connection to ms access. Below are my coding. try { ...
3
by: Andrea Raimondi | last post by:
Hello peers! I'm working on this application and I'm in need for some thoughtful advice :-p I have an SQLDataSource with params, select, etc. One of my params is the table name, which can be...
0
by: tvnaidu | last post by:
database file gets created using below sql file, then lua script calls "db.import config_ascc", then I get errors says "insert table failed for eventLog", below are my sql file entry, config file,...
3
by: tvnaidu | last post by:
When I do INSERT like below, value is a string with apastrophe (for ex: "Checking for 'hlt' instruction"), insert throws an error - how to fix? INSERT INTO table_name (column1, column2,...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.