473,394 Members | 1,781 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,394 software developers and data experts.

How can I use a variable value as a table field name in Access?

I need to use a variable value as a table field name. But when I ran the code, it gave me error and didn't use variable value but used the variable as the field name. I defined the following Sub and in my main Sub I call this Sub to input variable D, then the updating query will update the field where field name is matched with the variable D value.

Expand|Select|Wrap|Line Numbers
  1. Public Sub HC(D As String)
  2.  
  3.     Dim db As DAO.Database
  4.     Dim strSQL As String
  5.     Dim str1 As String
  6.  
  7.     strSQL = "UPDATE [HC Table] INNER JOIN [Previous Day Balances] " _
  8.            & " ON ([HC Table].Loan = [Previous Day Balances].loannum) " _
  9.            & " AND ([HC Table].Seq = [Previous Day Balances].seq) " _
  10.            & " AND ([HC Table].[Claim Type] = [Previous Day Balances].[Claim Type]) " _
  11.            & " SET [HC Table].D = [Previous Day Balances].[net_claim_balance] " _
  12.            & " WHERE ((([Previous Day Balances].net_claim_balance)<>0));"
  13.  
  14.  
  15.     DoCmd.RunSQL strSQL
  16.  
  17. End Sub 
Please help me Thx.
Jul 18 '13 #1
3 2076
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code.

You are in the wrong forum. Your thread has been moved to the Access forum.

You need to append the value of the variable to the string you're building. Not include the variable as a string.
Expand|Select|Wrap|Line Numbers
  1. " ... " & variableName & " ... "
Jul 18 '13 #2
Thx for the reply and help me moving to the correct forum.
Jul 18 '13 #3
Killer42
8,435 Expert 8TB
Just a tip - I think you'll make things much easier on yourself in the future if you use meaningful variable names. If you're maintaining a program you wrote months or years ago, a name like D is likely to tell you very little about what it's for.
Jul 20 '13 #4

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

Similar topics

2
by: my | last post by:
Hi All, I have one question. Usually, we can get data from table by using rst("userid") because we know the column name userid. Now, I have a variable to hold the column name. I want to get...
3
by: MLH | last post by:
Generally, I do not monkey with renaming controls on forms whose name, by default, matches the name of their related table fields. But I noticed the following today If IsNull(Me!VColor) Then...
3
by: prabhukumarasamy | last post by:
Now i m working in a existing project. I have to do some updations. In that project database table contain a table(usergroups) field name as 'Name'. When i am trying to insert a new record in...
1
by: John | last post by:
Hi I have two fields field1 and field2 on my form. Is there a way that the field names can be accessed via variable so that choice of the actual field to access is decided at runtime? Thanks...
15
by: Ajani | last post by:
Hello Good Morning, I am currently trying to change the Caption Property value within a table by allowing the user to type into a textbox and then click on the Submit button to change the Caption...
1
by: Ke0EE | last post by:
I am trying to use a record field date as the field name of a different table. Function SetChangeOnInactive() ' This routine will set the Closed Area change flag if someone with ' Open/Close...
1
by: STUFIX | last post by:
Hi, I need to change a field name in a table stored on a backend database that is used by various queries, forms, etc on the front end client via a linked table. I can't work out how to change...
3
by: adiel_g | last post by:
Hello everyone, I am trying to move a field name to a variable in vb.net. For example, first I retrieve the record from the database and save its value: .... userGroup =...
3
by: coolminded | last post by:
hi all, can i pass field name of a table as a parameter in a function created in postgres, what i mean is i have one table :student with field names id name add. can i create a function...
5
by: parry2k | last post by:
I have one view with 3 fields like the view name is myview and it has following sql statement. select fn,ln,city from tablea I created a function like below:- create function myfun(in t...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.