Modules & VBA :: Checking Array - Subscript Is Out Of Range If Value Is Equal To D

Aug 6, 2013

I am having trouble checking if the last array value is equal to 'D'.

This is what i have so far but it keeps saying that 'subscript is out of range'... 'g' by the way is equal to 1. It just really means that there's only one value in ArrAC.

Code : If Not ArrAC(g) = "D" Then

View Replies


ADVERTISEMENT

Modules & VBA :: Subscript Out Of Range If Run Twice

Sep 4, 2014

The below code exports a table (via a function) to a spreadsheet and saves it in a defined location. the code then opens the file does some work with it then moves it(left the move bit out as it works fine)

so when i run the code it works absolutle fine, table is exported, work is done and file is moved. however if i run the code again it fails, i get the error message out of range. i was originally getting this error when using the .usedrange.copy so i commented this out and now i get it on the next line that tries to work with the file so obviously something is wrong in my logic.

Code:
Private Sub Export2JDE_Click()
Application.Run ("JDE_Export") 'Exports to an xlsx file in the location described in the function.
Dim xlApp As excel.Application
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True

[Code] .....

View 8 Replies View Related

Modules & VBA :: Subscript Out Of Range In Excel Worksheet

Sep 10, 2013

I have written the following program code:

Dim xlApp As New Excel.Application
Dim xlwrkBk As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim strXLS As String
strXLS = "c:AccessMyfile.xls"
Set xlwrkBk = xlApp.Workbooks.Open(strXLS)

[code]...

The program is stopping at " Set xlSheet = xlwrkBk.Worksheets("singles")"

and I am receiving the following error box:

Runtime error 9

Subscript out of range.

I don't understand this error because I am using the same program code with another Excel file in another module and it works perfectly.

View 6 Replies View Related

Subscript Out Of Range Error....

Dec 5, 2007

I'm attempting to upload an excel file into access table using the wizard however I get this error message "subscript out of range" Please Help! I've uploaded other files via excel and don't have this problem.

Thanks
Kon

View 1 Replies View Related

Error #9 : Subscript Out Of Range

Jul 24, 2006

Ok I have the following code which keeps producing an Error # 9 : subscript out of range.....


Public Sub SaveLineItems()
On Error GoTo SaveLineItem_Error
MsgBox "I am doing the line items"
Dim sSQL As String
Dim iLine As Integer
Dim iMaxLines As Integer
Dim iMonthCount As Integer
Dim iFieldCount As Integer
Dim sThisField As String
Dim sFieldPrefix As String
Dim aFields, aMonths, sInDirectCostId, sFY, sUser
sFY = [Forms]![SWITCHBOARD]![cboFY]
sUser = [Forms]![SWITCHBOARD]![txtUser]
sInDirectCostId = sFY & sUser
aFields = Array("cboDesc", "txt", "txtMemo")
aMonths = Array("OCT", "NOV", "DEC", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP")
iMonthLoop = 0
iMonthCount = 11
iMaxLines = 16
iLine = 1
Do While iLine <= iMaxLines
iMonthLoop = 0
If Me.Controls(aFields(0) & iLine) <> "" And Me.Controls(aFields(0) & iLine).Locked = True Then
If Me.Controls(aFields(0) & iLine).Column(2) = -1 And Me.Controls(aFields(3) & iLine) = "" Then
MsgBox "You must have a memo for the program : " & Me.Controls(aFields(0) & iLine), vbOKOnly, "Missing Information"
Me.Controls(aFields(3) & iLine).SetFocus
Exit Sub
Else
sSQL = "UPDATE BUDGET_INDIRECTCOSTS_R_LINEDETAILS SET " & _
"ProgramId = " & Me.Controls(aFields(0) & iLine) & ", " & _
"Memo = " & Me.Controls(aFields(2) & iLine) & ", "
Do While iMonthLoop <= iMonthCount
sSQL = sSQL & aMonths(iMonthLoop) & " = " & Me.Controls(aFields(1) & aMonths(iMonthLoop) & iLine)
If iMonthLoop < iMonthCount Then
sSQL = sSQL & ", "
End If
iMonthLoop = iMonthLoop + 1
Loop
sSQL = sSQL & " WHERE INDIRECTCOSTID = " & sInDirectCostId & " AND ID " = iLine
End If
ElseIf Me.Controls(aFields(0) & iLine) <> "" Then
If Me.Controls(aFields(0) & iLine).Column(2) = -1 And Me.Controls(aFields(3) & iLine) = "" Then
MsgBox "You must have a memo for the program : " & Me.Controls(aFields(0) & iLine), vbOKOnly, "Missing Information"
Me.Controls(aFields(3) & iLine).SetFocus
Exit Sub
Else
sSQL = "INSERT INTO BUDGET_INDIRECTCOSTS_R_LINEDETAILS " & _
"(Id, ProgramId, Memo"
Do While iMonthLoop <= iMonthCount
sSQL = sSQL & ", " & aMonths(iMonthLoop)
If iMonthLoop = iMonthCount Then
sSQL = sSQL & ") VALUES ("
End If
iMonthLoop = iMonthLoop + 1
Loop
iMonthLoop = 0
sSQL = sSQL & "" & iLine & ",'" & Me.Controls(aFields(0) & iLine) & "','" & Me.Controls(aFields(2) & iLine) & "'"
Do While iMonthLoop <= iMonthCount
sSQL = sSQL & ", " & Me.Controls(aFields(1) & aMonths(iMonthLoop) & iLine)
If iMonthLoop = iMonthCount Then
sSQL = sSQL & ")"
End If
iMonthLoop = iMonthLoop + 1
Loop
End If
End If
MsgBox sSQL
If Len(Trim(sSQL)) > 0 Then
Set db = CurrentDb
db.Execute sSQL
End If
iLine = iLine + 1
Loop
SaveLineItem_Error:
If Err.Number <> 0 Then
MsgBox "Line Item Save Error : " & Err.Number & vbCrLf & Err.Description
End If
End Sub


I have gone through and commented everything out and brought back only parts and here is what I have when I get the error the first time....


Public Sub SaveLineItems()
On Error GoTo SaveLineItem_Error
MsgBox "I am doing the line items"
Dim sSQL As String
Dim iLine As Integer
Dim iMaxLines As Integer
Dim iMonthCount As Integer
Dim iFieldCount As Integer
Dim sThisField As String
Dim sFieldPrefix As String
Dim aFields, aMonths, sInDirectCostId, sFY, sUser
sFY = [Forms]![SWITCHBOARD]![cboFY]
sUser = [Forms]![SWITCHBOARD]![txtUser]
sInDirectCostId = sFY & sUser
aFields = Array("cboDesc", "txt", "txtMemo")
aMonths = Array("OCT", "NOV", "DEC", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP")
iMonthLoop = 0
iMonthCount = 11
iMaxLines = 16
iLine = 1
Do While iLine <= iMaxLines
iMonthLoop = 0
If Me.Controls(aFields(0) & iLine) <> "" And Me.Controls(aFields(0) & iLine).Locked = True Then
If Me.Controls(aFields(0) & iLine).Column(2) = -1 And Me.Controls(aFields(3) & iLine) = "" Then
MsgBox "You must have a memo for the program : " & Me.Controls(aFields(0) & iLine), vbOKOnly, "Missing Information"
End If
ElseIf Me.Controls(aFields(0) & iLine) <> "" Then
If Me.Controls(aFields(0) & iLine).Column(2) = -1 And Me.Controls(aFields(3) & iLine) = "" Then
MsgBox "You must have a memo for the program : " & Me.Controls(aFields(0) & iLine), vbOKOnly, "Missing Information"
End If
End If
iLine = iLine + 1
Loop
SaveLineItem_Error:
If Err.Number <> 0 Then
MsgBox "Line Item Save Error : " & Err.Number & vbCrLf & Err.Description
End If
End Sub


I have gone and researched the problem and have not been able to find anything that relates to this......

Thanks,
Richard

View 1 Replies View Related

General :: Subscript Out Of Range In VBA

Jun 6, 2014

What the Variant value on Ms Access latest version is same with Ms Access previously(97,2003).?

I am using office 2010

I have face error again in line

Code:
-----------------------------------------
bd = ""
bd = Split(bx(1), " ")
For i = 0 To (UBound(bd) - 1)
Me("p" & i).Caption = bd(i)
Me("p" & i).Visible = True

[Code] .....

View 12 Replies View Related

General :: Subscript Is Out Of Range

Aug 13, 2013

When I try to import a sheet from Excel into an existing table I get a subscript out of range error.When I then import the sheet into a new table and then import it into the existing table I was trying above immediately afterwards it works fin.

View 1 Replies View Related

Error - Subscript Out Of Range

Aug 14, 2013

When I try to import a sheet from Excel into an existing table I get a subscript out of range error.

When I then import the sheet into a new table and then import it into the existing table I was trying above immediately afterwards it works fine.

View 3 Replies View Related

Subscript Out Of Range Error

Sep 16, 2010

I am trying to import data from Excel 2007 to Access 2007. However, after hitting the final button to submit the import I get this message: "Subscript out of range."

I have tracked down the fields that seem to be causing the problem. Below is a picture of the Design View for my table. The fields named Ht, College, Dob, State, and Country are the fields that give me the subscript message (I know this because I tried uploading different times with just one of these fields mixed in with the fields that would upload). My first guess for the Height was just a matter of the data type being wrong, but I changed the Ht column to text on my Excel spreadsheet and the same message occurs.

College: Is listed in the picture. This is being pulled from another table. I have another field labeled Transfer College that does this as well, but the expression is a bit different, and any data in a Transfer College column on excel will import over. I have tried altering the College data type to match the Transfer college, but I have to delete too many relationships and it screws up the record source for all of my forms and reports.

DoB: It has an input mask of: 99/99/0000;0;" " Not sure why this doesn't work. Access seems to be picky with dates. When going through the import steps it changes my dates in my spreadsheet to a 5 digit number.

State: Again, another combo box with a value list. State abbreviations are the record source. I would think this would upload. Should I just remove the combo box and value list for now, and then reset this after I transfer my data over?

Country: Another combo box, but this one is pulling its data from a table with countries listed.

View 14 Replies View Related

Reports :: Subscript Out Of Range In Report Wizard

Sep 10, 2013

I am trying to generate a report from a select query using the report wizard. The wizard is showing the error of subscript of out range. What is the reason and how can be rectified?

View 4 Replies View Related

Importing From Excel - Error Message Subscript Out Of Range

Jan 11, 2015

Trying to import data from Excel into an existing table in Access 2007. The import fails and keeps getting the error message: "subscript out of range". All of the column headings in the 1st row are exactly the same as the table in Access, and the data types are all text except for the key which is a number. I've imported to this table many times and not had a problem and can't figure this out.

View 3 Replies View Related

Modules & VBA :: On Event Value Is Equal To Last Saturday

Jan 22, 2015

How do I do: on event enter last saturday (in a control)?

The best I've been able to come up with is to check if it's A saturday.

Code:
Private Sub ctrl_Weekending_Exit(Cancel As Integer)
Dim strDay As Integer
strDay = Nz(Weekday(Me.ctrl_Weekending.Value, vbSaturday))

[Code].....

View 4 Replies View Related

Modules & VBA :: Send OpenArgs As Array?

Apr 28, 2015

Is it possible to send several form's OpnArg as Array ? Now I'm using a long text string including || as divider so I can split them later into Array.

View 8 Replies View Related

Modules & VBA :: Parsing Array Value To Form

Nov 14, 2013

I am having a problem with parsing the array value to Forms!<arraryvaluehere>.dirty.

Please see the code below:

Public strListOfForms(0 To 2) As String
strListOfForms(0) = "frmForm1"
strListOfForms(1) = "frmForm2"
strListOfForms(2) = "frmForm3"
For i = 0 To 2

Debug.Print CurrentProject.AllForms(strListOfForms(i)).IsLoaded
Debug.Print Forms!strListOfForms(i).Dirty

Next i

Note: CurrentProject.AllForms(strListOfForms(i)).IsLoade d works and Forms!strListOfForms(i).Dirty does not.

Is this because it is taking "strListOfForms(i)" literally? Is there a way that I can get around this?

View 1 Replies View Related

Modules & VBA :: Using Array To Populate ListBox

Apr 7, 2014

I have some code that successfully gathers some items and adds these items to a listbox, one item at a time using .AddItem.And it works ok.The problem is, when there are a bunch of items to add, everytime the .AddItem runs, the form redraws.there are a bunch and this leads to a lot of flicking while the form redraws however many times .AddItem adds an item.

I've had the idea of building an array and then assigning the array to the listbox.I can build the arrray no problem but i have not been able to assign the array to the listbox all at once.how to do is add items to the listbox from the array one specific item ListArray(i) at a time.

Obviously this would work, but gains me nothing in terms of the visual effect in the form becuase it is still adding to the listbox one item at a time.Is there some way to assign an array to a list box all at once, without doing it one item at a time?

View 3 Replies View Related

Modules & VBA :: Deleting Values In Array?

Jul 1, 2013

How do I delete values in an array? I want to reuse that array but first I need to delete its values so I would start with Arr(0) rather than where I stopped off with the last loop at Arr(10) [assuming the last calculation inserted until Arr(9)]

Here is my code:

Set rst = CurrentDb.OpenRecordset( _
"Select * from dbo_ProductStructure where ChildProductNbr Like '*" & txtPartNumber & "*'") 'search associated fields with user input
While rst.EOF = False
ReDim Preserve Arr(i)
Arr(i) = rst.Fields("ParentProductNbr")
i = i + 1
rst.MoveNext

Wend 'end of while loop

x = Arr

View 9 Replies View Related

Modules & VBA :: Empty Values In Array

Aug 16, 2013

I'm trying to store all the OrderNumber + Item combinations in 2 arrays and then because the OrderNumber column really contains 2 values I'm interested in, I split it up and store that column's values in 2 arrays. So in total, I have 3 arrays. An array for Item, an array for Order, and an array for RepId (which is the one that I split up from the OrderNumber column).

Anyways, when I print the RepId array with the ' MsgBox PostValCol1(x) ' It prints 4 values like it's supposed to. But when I tested it again by looping through the values and just doing a MsgBox, It goes for a long time and that's because it has a lot of empty values in that array. How to get rid of those empty values/not store them in the first place?

Code:

Set rop = CurrentDb.OpenRecordset("Select OrderNumber, ItemNumber From dbo_EntryStructure Where (ProductNumber = '" & txtPartNumber & "') AND (ActionCode = 'I')")

While rop.EOF = False
ReDim Preserve ArrRepOrder(j)
ReDim Preserve ArrItem(j)

[Code] .....

View 3 Replies View Related

Modules & VBA :: Retrieving Array Returned From PHP

Mar 11, 2014

I have an Access Database that I will be using on a desktop. I have a table in this database that mirrors the structure of a table on a remote server in a SQL database. I have successfully created a vba function within the Access database that uses a server-side php subroutine to select records (I usually won't know how many) from the SQL database and return them to the access database. The code I use in the access vba subroutine to access the php subroutine is:

Code:
With CreateObject("Shell.Application").Windows
Set ieWindow = CreateObject("InternetExplorer.Application")
ieWindow.Visible = False
apiShowWindow ieWindow.hwnd, SW_MAXIMIZE
ieWindow.Navigate "Web address for server-side php file"
End With

The last command in my php subroutine is "return $retrievedData." $retrievedData is a multidimensional array containing data from 42 fields in multiple records (again, I usually won't know how many). I've checked the data in php so I know it has been stored correctly.how do I access the returned data within my access vba subroutine?

I should add that my overall reason for doing it this way is that I want to maintain my server-side database as an untouched master. Users can only add data to it. My client-side database is used to update the input table and further process the data. The subroutines described above are intended to retrieve "new" records only (i.e., records posted since the last access database update) from the server-side database and transfer them to the access database for further processing.

View 3 Replies View Related

Modules & VBA :: Possible For A Msgbox To List All Records Where A Field Equal To Value?

May 18, 2015

So I have a form for addresses that checks against a table of US zip codes, and throws up a warning if the City/State/Zip entered isn't found on the table. This works great. But I was wondering if there was a way to list the available combinations based on the zip code entered. I want the program to tell the user that the city is wrong, but here is a list of what it could be.Is it possible for a msgbox to list all records where a field = value?

View 11 Replies View Related

Modules & VBA :: Check If A Textbox Is Equal To Todays Date

May 18, 2015

When a form in my database is loaded I want access to check if a textbox on the form is showing today's date and if not send me an email. I'm quite new to VBA so not 100% sure what to do but I've had a few attempts and none seem to work. I have managed what is probably the hard part and can get it to email me but can't seem to get the 'If the textbox is not today's date then' bit right.

The textbox is linked to a table and the data type is 'Date/Time', it does show the time and the date so don't know if this makes a difference? The text box is [DateUpdated] and the form is [Site].

View 1 Replies View Related

Modules & VBA :: Using Select Case Statement With Array?

Jun 26, 2014

I have a boolean array, foundState(3), whose 4 elements correspond to 4 variables describing conditions that will dictate what action is taken upon closing a form.

There are only 6 possible outcomes for the array, and they can be divided into just 4 cases:

Case {T,T,T,T}

Case {T,T,T,F} OR {T,T,F,F} OR {T,T,F,T}

Case {T,F,F,F}

Case {F,F,F,F}

What the proper syntax would be for this if I'm trying to create a "Select Case" statement for these 4 cases.

View 7 Replies View Related

Modules & VBA :: How To Make Array And For Each Statement Work Together

Aug 23, 2013

how I can make an Array and For Each statement work together. I normally don't use either, but it would be good so I could write less code where plausible. Here is the example I have:

Code:
Dim Named As Variant
Dim Ctl As Control
Named = Array(Me.Namee, Me.ID, Me.Title)

[code]....

I am unsure how I include the array in this statement. I have tried replacing "Me.Controls" with the array name, but I get a 424 runtime error (no object). What I am trying to accomplish is for each item in the array I want to make it not visible if it has a null value.

View 7 Replies View Related

Modules & VBA :: Find Duplicates Of Values In Array

Oct 4, 2014

I have to deal with string arrays that store text. I need info on copying, comparing, appending arrays. Also on passing arrays as parameters to subs or functions. Where I can get to this info quickly without having to browse through many screens.

In addition to this I have some questions:

I have to find the duplicates of values in an array. Here is the code that I use.

Code:
Sub FindDuplicates()
Dim I As Integer, J As Integer, IEND As Integer, text() As String
ReDim text(IEND)
For I = 1 To IEND - 1
For J = I + 1 To IEND
If text(I) = text(J) Then text(J) = ""
Next J
Next I
End Sub

It works but is not performing well. Are there more efficient ways of doing this?

View 14 Replies View Related

Modules & VBA :: How To Pass Only Single Dimension Of Array

Jul 31, 2014

Now the getrows is working fine at my end. Now I have a different problem at hand:

Sub Test2()
Dim myrset As Recordset
Set myrset = CurrentDb.OpenRecordset("SELECT * FROM Holidays;")
myrset.MoveLast

[Code]....

Recordcount is coming fine
Manual Array is also giving the right result
But the Index method is giving the wrong value. Why?

(Holidays table is just having the values in the array only ie. #08/15/2014# and #08/29/2014#)

View 7 Replies View Related

Modules & VBA :: How To Read TXT File Into Array For Processing

Oct 23, 2014

I'm getting an error when trying to read a .txt file into an array for processing. The error and a snippet of the code are below.

Run-time error '9'
Subscript out of range

Dim iFileNum As String
Dim strLineInfo()
Dim i As Integer
Dim strExpensesFile As String
strExpensesFile = "c:FinanceExpensesIn.Txt"

[Code] .....

View 9 Replies View Related

Modules & VBA :: Upload CSV To Array And Then Add Records To Table

Jun 9, 2013

I'm trying to upload a csv file into an Array then add records to a table. I have the following code which gets the information from a csv file which works fine.

Open filePath For Input As #1
Do While Not EOF(1)
Line Input #1, MyData

Problems:
1. When i try to load this into an array , it does not return all the information. It will if a smaller amount of data is sought. For example if only 1 months month of data is requested. Is there a maximum data limit that can be parsed into an array with this method?

2. I'm not quite sure how to parse individual lines (records) to update a table in access. I have provided the code that I'm trying to use to accomplish this below. From code below am I doing this correctly?

3. For each record that is created in the database I would like to add a ticker string to the record for later querying. Can this be done and am I on the right track from the supplied code?

Private Sub ImportData(filePath As String, ticker As String)
'On Error GoTo Errorhandler
Dim arrData() As String
Dim MyData As String
Dim i As Integer
Dim Db As DAO.Database

[Code] ....

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved