Solved

SubScript Out of Range

Posted on 2007-04-01
7
319 Views
Last Modified: 2013-11-28
I am trying to update a table named OperationRiskData if a user hit the Save Button on the Form . I have following code in onClick
---------------------------------Code---------------------------------------------
rivate Function ExecuteSQL() As Boolean
Dim sql As String
sql = "insert into OperationRiskData(Branch Name, Review Date,Branch Code,OpsManager Name,Event Description,Event Classification,Example,Business Lines,Approximate Amount,Action Taken,Action Date)" & _
 "values(CmbBranchName, DOB,txtBranchCode,Opsmanager,CboEvent,CboClassification,CboExample,txtbusinessline,txtamount,txtaction,txtdate);"
CmbBranchName = Forms![frmBranchInfo].CmbBranchName
DOB = Forms![frmBranchInfo].DOB
txtBranchCode = Forms![frmBranchInfo].txtBranchCode
Opsmanager = Forms![frmBranchInfo].Opsmanager
CboEvent = Forms![frmBranchInfo].CboEvent
Cboclassification = Forms![frmBranchInfo].Cboclassification
CboExample = Forms![frmBranchInfo].CboExample
txtbusinessline = Forms![frmBranchInfo].txtbusinessline
txtamount = Forms![frmBranchInfo].txtamount
txtaction = Forms![frmBranchInfo].txtaction
txtdate = Forms![frmBranchInfo].txtdate
DoCmd.RunSQL sql
End Function
---------------------------End Code--------------------------
--------Error Message that i am getting
The Expression Onclick you entered as the event property setting produced the following error ;SubScript Out of Range.
*The  Expression may not result the name of a macro or event
*There may have been an error evaluating the function or macro
0
Comment
Question by:tgatif
  • 4
  • 3
7 Comments
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 18834836
You have to turn it upside-down: Define the variables, build the SQL, then run the SQL:

CmbBranchName = Forms![frmBranchInfo].CmbBranchName
DOB = Forms![frmBranchInfo].DOB
txtBranchCode = Forms![frmBranchInfo].txtBranchCode
Opsmanager = Forms![frmBranchInfo].Opsmanager
CboEvent = Forms![frmBranchInfo].CboEvent
Cboclassification = Forms![frmBranchInfo].Cboclassification
CboExample = Forms![frmBranchInfo].CboExample
txtbusinessline = Forms![frmBranchInfo].txtbusinessline
txtamount = Forms![frmBranchInfo].txtamount
txtaction = Forms![frmBranchInfo].txtaction
txtdate = Forms![frmBranchInfo].txtdate

sql = "insert into OperationRiskData(Branch Name, Review Date,Branch Code,OpsManager Name,Event Description,Event Classification,Example,Business Lines,Approximate Amount,Action Taken,Action Date)" & _
 "values('" & CmbBranchName & "', # & Format(DOB, "m\/d\/yyyy") & "#, '" & txtBranchCode & "', '" & ... etc. etc.
 
DoCmd.RunSQL sql

/gustav
0
 

Author Comment

by:tgatif
ID: 18835000
Can u explain to me the syntax of values, i am just struggling with access
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 18835018
String must be wrapped in quotes:
  'some string'
dates in hash marks (and US-formatted as shown):
  #3/31/2007#
decimal numbers with dot as decimal separator:
  456.78
 - use Str() for this: strDecimal = Str(yourdecimalvalue)
and integer values 'as is':
  1234

/gustav
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:tgatif
ID: 18835074
It is still giving me error "Expected end of statement" here is the SQL . The error occurs at the value and specifically at the date formate ( "m\/d\/yyyy).
Is it part of syntax to have backward and forward slash in the date format or is it typo........
here is Sql
---------------------------------------------------------------------------------------
sql = "insert into OperationRiskData(Branch Name, Review Date,Branch Code,OpsManager Name,Event Description,Event Classification,Example,Business Lines,Approximate Amount,Action Taken,Action Date)" & _
 "values('" & CmbBranchName & "', # & Format(DOB, "m\/d\/yyyy") & "#, '" & txtBranchCode & "', '" & Opsmanager & "','" & CboEvent & "','" & Cboclassification & "'," & CboExample & "'," & txtbusinessline & "'," & txtamount & "'," & txtaction & "',# & Format(txtdate, "m/d\/yyyy") & "#)"
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 125 total points
ID: 18835101
You have to have symmetrical quotes:

"values('" & CmbBranchName & "', #" & Format(DOB, "m\/d\/yyyy") & "#, '" & txtBranchCode & "', '" & Opsmanager & "','" & CboEvent & "','" & Cboclassification & "','" & CboExample & "','" & txtbusinessline & "'," & Str(txtamount) & ",'" & txtaction & "',#" & Format(txtdate, "m/d\/yyyy") & "#)"

/gustav
0
 

Author Comment

by:tgatif
ID: 18835168
One more thing if i have a combo box say Branch Names and a text Box on a form, what i want is when i select the option in combo box the corresponding values in the text box will appear and is saved in the table . what i did is i have in control Source i have =CmbBranchName.Column(0)
CmbBranchName is branch name combo .
Problem is the branch code value  do not go to corresponding table all i have is 0 in the branch code Column .
is there a utilityi can upload my database and u can take a look,,,,,,,just thinking  
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 18835210
If the textbox is bound to CmbBranchName:

  =CmbBranchName.Column(0)

it is not bound to the table.

You may use the AfterUpdate event of the combobox to set the field of the table:

  Me!NameOfFieldInTable = Me!CmbBranchName.Column(0)

/gustav
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now