473,788 Members | 2,988 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I INSERT INTO a table a variable value

14 New Member
Here is my code. I am trying to INSERT INTO "Master_Tab le" 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 1969
NeoPa
32,578 Recognized Expert Moderator MVP
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 New Member
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_Tab le" field "Edited_By" the value of the variable "Editor". I dont know how else to say it.
Sep 15 '10 #3
NeoPa
32,578 Recognized Expert Moderator MVP
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 Contributor
What is this lonely "End" doing on line #30?
Sep 15 '10 #5
JonHuff
14 New Member
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
7023
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
3199
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. Thanks
2
16035
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 column A is XXX, then change it to YYY, and proceed with the insert. Not sure how to do this though. Only noob @ triggers. I managed to do a trigger which AFTER an insert, checks column in item table for value 8 & then sets it to 0. can anyone...
2
3387
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 1~12 to represent months, but I want to show them as Jan/.../Dec. So I thought I could write a simple function to convert it and call that function in the Bind expression of DataList. However, I just couldn't find a way to pass the bind...
0
1255
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 then that progress bar should start and it should stop when the variable that I am passing in the javascript becomes greater than 1. That variable value starts with zero and it increases after making a call to another function called func.
2
4391
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 should be able to replace the %name% with a variable value and i also need to have the ability to change the possessions.(just by changing the string in my database).
2
6111
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 { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // set the connection for database path String Database_Path = "E:/Segi/Project/Coding/Car_Park_Storage.mdb";
3
2846
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 programmatically set, this is necessary because I may have a simple table name or a union, hence I got to pick the correct one! Unfortunately, I can't bind this parameter to a control, session or
0
1489
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, also import and saveTable function, any idea what is wrong, why I get error?. thanks in advance. system.sql file ========== CREATE TABLE eventLog ( component text NOT NULL,
3
2658
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, column3,...) VALUES (value1, value2, value3,...)
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10364
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.