General :: Loop Function With Variable

Jun 4, 2015

I want to make a loop like this:

Dim var1 As Variant, var2 As Variant, var3 As Variant, var4 As Variant
DIm var5 As Variant, var6 As Variant, var7 As Variant, var8 As Variant
Dim var9 As Variant, var10 As Variant
Dim i1 As Long
i1 = 1
Do Until i1 > 10
var & i1 ??? = "0" & i1 & "." & txt1 & "." & txt2
i1 = i1 + 1
Loop

How to make concatenate var + i1 to make loop function?

View Replies


ADVERTISEMENT

Modules & VBA :: Build Loop Into A Variable

Jul 19, 2014

I am relatively new to VBA and have this loop (see below) was wondering if it was possible to build it into a variable, so I could call upon it within an IF statement.

Set ctl = Me.listSeeAllAssets
For Each varItem In ctl.ItemsSelected
rs1.AddNew
rs1!AssetNo = ctl.ItemData(varItem)
rs1!DateOfService = Me.DateOfService

[Code] .....

View 7 Replies View Related

Create A Loop That Searches Through A Table And Increments A Variable

Apr 22, 2012

Im trying to create a loop that searches through a table and increments a variable every time it finds a record with a specific field set to a specific value. Below is the code but its not working. I then use the variable for another field.This is used in a form btw.

Dim counter As Integer
counter = 0
Set rst = CurrentDb.OpenRecordset("TableName")
Do Until rst.EOF
If rst(10) = "True" Then
counter = counter + 1
End If

rst.MoveNext
Loop
Me.Text24 = counter

View 12 Replies View Related

Modules & VBA :: Writing To Text Boxes On A Form Variable / Loop

Nov 16, 2014

I some code that is reading the first 32 lines of a text file and paste the results into 1 text box on individual lines. I would like each line to go into an individual text box.

I have 32 text boxes named txt_1, txt_2, txt_3
I have a variable named ThisLine holding the line of the text file.
I have a variable named textBoxName holding the name of the control.

Need to putting these together to write the line to a text box .

Code:
Sub ReadFile()
Me.txt_newData = ""
Me.txt_OrigData = ""
'again, we need this strange thing to exist so that ...
Dim fso As New FileSystemObject

[Code] .....

View 1 Replies View Related

If Function And Loop

Mar 8, 2007

Hey all,

I'm trying to make a code in asp that will allow comments to be presented to teh enduser relevent to the article they are reading.

I'm am using a access database to hold the info and each article is given a unique id.

My code is as such:

<%
Dim adoCon
Dim rsGuestbook
Dim strSQL
Dim adid
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("comment.mdb")
Set rsGuestbook = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT tblComment.id, tblComment.name FROM tblComment;"
adid = Request.QueryString("id")
rsGuestbook.Open strSQL, adoCon

Do While not rsGuestbook.EOF
if (adid=rsGuestbook("id")) then
Response.Write (rsGuestbook("name"))
else
end if
rsGuestbook.MoveNext
Loop

rsGuestbook.Close
Set rsGuestbook = Nothing
Set adoCon = Nothing
%>

However the if fuction does not seem to be working, any ideas would be extremely helpful.

Regards

Vikram

View 1 Replies View Related

Modules & VBA :: Loop Function Repeating First Line Of Recordset

Aug 17, 2015

managed to get some code up and running but when trying to enhance it I have hit a rut.

I have a function that is looking up a query called Optimisation - Auto Optimise with operational data in it. I only need 2 key fields; consolcode and volume. There are 106 records with different consolcodes each with different volume. e.g consolcode: Chittagong to Rotterdam201452 (Chittagong to Rotterdam by year "2014" by week "52") and volume 161 (cbm)

I then run a code that allocates the volume into specific sea freight containers and returns the values into a different output table.

The allocation code works fine but when I run the loop function for the recordset rsttradelane it runs for the correct amount of records (106) but always returns the first record of Chittagong to Rotterdam201452 and 161 cbm and not the other 105 consolcodes with the different cbm. Giving me an output table with Chittagong to Rotterdam201452 and 161 cbm repeated 105 times!!

Code:
Set rsttradelane = dbsEPIC.OpenRecordset("Optimisation - Auto Optimise")
consollane = rsttradelane!consolcode
ConsolVol = rsttradelane!Volume
Do Until rsttradelane.EOF
'Optimisation code' then
Code:
rsttradelane.MoveNext
Loop
rsttradelane.Close

How do I ensure that each consolcode and its associated cbm is recognised individually and flushed through the optimisation code?

View 3 Replies View Related

Modules & VBA :: Variable Value Not Getting Stored In Function

Sep 8, 2014

I defined a public variable and then for being able to filter a query results, assigned it to a public function. The problem is that function doesn't get the variable's value.

View 14 Replies View Related

Forms :: How To Call A Function From A Variable

Apr 5, 2014

I have the following in Form and it works OK

Call RunForm("frmProviderLookup", "", "Edit", "", "", "Normal", "Normal")

I want to build a combo box with several different RunForm variations as follows:

RunForm("frmProviderLookup", "", "Edit", "", "", "Normal", "Normal")
RunForm("frmCustomerLookup", "", "Edit", "", "", "Normal", "Normal")
RunForm("frmVendorLookup", "", "Edit", "", "", "Normal", "Normal")
etc, there are many of these

When I select one the variations from the combo box the RunForm statement is stored in strAction varaible..How do I code the Call strAction line? (I want only one call statement).In other words how to call a Function from a variable...The start of my module Function works OK and looks like this:

Public Function RunForm(FormName As String, _
Optional WhereCondition As String = "", _
Optional xMode As String = "", _
Optional filterName As String = "", _
Optional Args As String = "", _
Optional WindowMode As String = "", _
Optional View As String = "")

' Parameters (all optional except parameter 1)
' 1 - Form Name
' 2 - Where condition
' 3 - Mode [Add, Edit, View(Read Only), ""(PropertySettings), DS(Datasheet Edit)]
' 4 - Filter Name
' 5 - Opening Arguments
' 6 - Window Mode
' 7 - Form View

View 1 Replies View Related

Modules & VBA :: Function - Can A String Be Optional Variable?

Aug 26, 2014

I am amending some Code I found online for an audit table, I need to store additional information in the table that is associated with some forms but not others.

I have researched about putting optional variables in, but I read this only works with the type VARIANT.

Is there a way to make a string optional as my fields contain text?

here is my code so far:

Sub AuditChanges(IDField As String, UserAction As String, Optional UserID As String, Optional DeviceID As String, Optional SimID As String)
On Error GoTo AuditChanges_Err
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim ctl As Control
Dim datTimeCheck As Date

[Code]...

View 5 Replies View Related

Modules & VBA :: Send Function Variable Back To Form

Apr 30, 2014

I have some code in a form that calls for a public function and passes on some values. the function makes some calculations and assigns a value to the variable "percent" in the function itself.

How can I get the value of this variable back in the form so I can use it?

Form:

Code:
Private Sub Form_Open(Cancel As Integer)
Dim Table As String, TotalFields As Single
Table = "tblAdmission"

[Code]....

View 5 Replies View Related

Modules & VBA :: Public Type (variable) For Function To Return More Than One Value

Sep 23, 2014

Question for Documentation purpose: Should the Public Type be declared in its own module?

Or should it be declared in a standard module where non-public functions use it? It is not for a Form module use.

For a Rule Engine, a function is calling one record on 4 different SQL Views (as linked tables) that have the same field format.

For speed, the recordset should only be opened once. However, there are multiple values that must be returned to the result table multiple fields.

One way to return multiple values is an Array. That has over head too.

Another way is to create multiple public variables. Not my choice for documentation. Another is to create a string.

This is a pure code module with several non public functions / subs. What is the documentation preference? List a Public Type close to the function, or place it in the Global module?

Background: A function can only have one return value.

By creating a public Type, multiple values can be returned.

Code:
Public Type Income
Wages As Currency
Dividends As Currency
Other As Currency
Total As Currency
End Type

Use this structure as the return type for a function. In a real situation, the function would look up your database tables to get the values, but the return values would be assigned like this:

Code:
Function GetIncome() As Income
GetIncome.Wages = 950
GetIncome.Dividends = 570
GetIncome.Other = 52
GetIncome.Total = GetIncome.Wages + GetIncome.Dividends + GetIncome.Other
End Function

To use the function, you could type into the Immediate Window:

GetIncome().Wages

(Note: the use of "Public" in the Type declaration gives it sufficient scope.)

Important Notice The way this function is called will work, but is wrong from the aspect it re-calls the recordset over and over.

See the proper way to use it submitted below.

View 5 Replies View Related

Modules & VBA :: Using Public Function To Feed A Variable String To Query

Feb 26, 2014

I am using a public function to feed a variable string to a query. So far I have got:

Code:
Public Function ClientStreetModule(firstLVar As Variant, streetVar As Variant, newFL As Variant) As String
Dim cslStr1 As String, newStreet As String
newStreet = Right(streetVar, Len(streetVar) - Len(newFL))

[code]....

However, I only need to use newStreet as the true part of iif, in which instance all are longer. At least I think this is the problem. I realise I might need to use NZ but am not sure how. Why it is evaluating and giving errors for all records and not just when the iif criteria is true as I want it to?

View 7 Replies View Related

General :: Loop Through Query For Information

Jun 18, 2014

I am using Access 2010. I have a database that on a form uses a multiselect listbox. That part works just fine. The list box is for selecting additional people to email. Now I have had no luck with returning just the email address that are in a hidden column (the persons actual name is seen and "selected"). The names come from a separate table and is used as a forgien key. On that same table are the indivuals email addresses. What I did was loop through to get all of the ID numbers I am getting from the list box (the ID numbers are stored in the table that the form is based on).

Once I have all of the ID Numbers I thought that maybe there was a way to retrieve all of the email address associated with the ID Numbers. This is what I have so far. I know that AllQuery returns the first email address from the list box. I just have no idea if the query is returning more than one record, or if it is how to then go to the next record. I have tried a few things with little to no success.

Code:
Dim ListItem As Variant
Dim AllItems As String
Dim AllQuery As String
For Each ListItem In Me.EmailAdditionEgineers.ItemsSelected
AllItems = AllItems & Me.EmailAdditionEgineers.ItemData(ListItem) & " or "
Next ListItem
AllItems = Left(AllItems, Len(AllItems) - 3)
AllQuery = DLookup("EmailAddress", "AdditionalEmailRequestQuery", "[ID] = " & AllItems) & ";"

View 11 Replies View Related

General :: Loop - From One Continuous Subform To Another

May 21, 2014

I have attached an image of what i am trying to achieve so here goes:

I need to add data from one subform to another - problem is they are both continuous forms and both subforms.

The part in green is where it needs to go, and the white is where the data is held. The links have already been created, i just need to get the info from subform 1 to subform 2.

I have attached code but it only moves line selected / first line.

Dim dst As DAO.Recordset
Set dst = Me.frmAS9102_Material_LINK.Form.RecordsetClone
With dst
.MoveFirst
Do While Not .EOF

[Code] .....

View 4 Replies View Related

General :: Loop Through Listbox Records

Feb 15, 2014

I am looking to loop through all of the rows in a listbox. For each row in the listbox, I want to check if the last name in the Labor column is contained in any records in the Labor column of a recordset. If it is contained, add the column value to a variable to eventually be shown in another listbox. It seems that the loop is not working correctly and the EstHours is always 0 and the instr function doesn't seem to be working.

Code:
Sub ScheduledHours()
'on error goto errorhandler
Dim LastName As String
Dim FullName As Variant
Dim EstHours As Long

[Code] ......

View 3 Replies View Related

General :: Loop Through Resordset - Download Each Of Records One At A Time

Apr 14, 2014

I'm trying to 'Loop' through a recordset (i.e. "newRS") that has 46 records in it. I get the recordset as follows:

Code:

set newRS = currentdb.openrecordset ("PO Table")
newRS.movefirst

I want to download each of the records, one at a time, into Excel. To do this, I'm use the following:

Do until newRS.EOF = True

Several intermediate steps within the loop that aren't relevant to my problem

Set mySheet = myWB.Worksheets("db POLabel")
mySheet.Range("A2").CopyFromRecordset newRS
newRS.Movenext
Loop

Right after the 'Copyrecordset' command executes, the recordset cursor seems to be jumping to the end of the recordset and I get the following error message (when the code tries to execute the 'Movenext'):

'Run-time error: 3021: No current record'

View 2 Replies View Related

General :: SQL Statement Using A Variable

Feb 25, 2014

Is there a way to use a variable in an SQL statement?

Something like this:

Code:

dim mysql1, newname
newname = inputbox("direction on what to do go here?",,)
mysql1 = "INSERT INTO FinalAll SELECT newname.* FROM newname;"
DoCmd.RunSQL mysql1

Where newname would be a variable assigned from an input box.

I want to populate a single table from several different tables but have the user specify which tables to use.

View 8 Replies View Related

General :: Variable As FieldName In DLookup

Aug 12, 2014

I want to use a variable as FieldName in the DLookup function.

Normal DLookup:

Code:
DLookup("FieldName" , "TableName" , "Criteria= 'string'")

I want to use:

Code:
DLookup(variable, "TableName", "Criteria= 'string'")

Where variable is an integer, which represents the column number in the table.

Is this possible?

View 7 Replies View Related

General :: Using Variable Between HTML Tags?

Sep 30, 2012

TextBox1 is Rich Text:-

I want to replace my String ("Evidence required of this please" ) in this code 1) following which works fine, with a variable (textToPaste) as in code 2) which doesn't work.

1) TextBox1 = "<div><font style=""BACKGROUND-COLOR:#FFFF00"">Evidence required of this please</font>"

2) TextBox1 = "<div><font style=""BACKGROUND-COLOR:#FFFF00"">textToPaste</font>"

Can I persuade the statement to accept "textToPaste" as a variable and not a normal string?

View 3 Replies View Related

General :: For Control Variable Already In Use Error

Apr 15, 2014

Code:
Private Sub CommandButton3_Click()
Dim rngCell As Range
Dim i As Long
Application.ScreenUpdating = False
'Coverage code
i = Range("J" & Rows.Count).End(xlUp).Row

[Code] ....

Why doesn't access like the underlined (For control variable already in use).

View 3 Replies View Related

General :: Variable Button Label

Oct 28, 2014

I have a printed form that pulls some of its data from a table.What i need is that printed form to have a variable that two area in the form can change based on who is printing the form.I have a table that has all the users data in it. the current form pulls that information from the label and places it into the for. easy enough so far right.

for example. But i need this printed form to be able to be dynamic. So for instance Tom inst sitting that the computer wanting to print the form and so on for four different users who will print the form.So the button that allows the print either needs a way to have a selection or i need four different button. So the second part of this Mark Twain quits his job and Johnny takes his place. easy enough to change the data in the table that my form is pulling the data from but the button label needs to change to that the button.

View 7 Replies View Related

General :: Select Top 100 In Query Variable Text Box

Nov 6, 2012

i have got a query that returns the top 100 results. i would like to link this to my report form where i have a text box that you can enter a number and the query returns the first of that ammount rather than going into the query everytime to adjust the results.the sql of the query is as follows

PHP Code:

SELECT TOP 100 tblClientDetails.FirstName, tblClientDetails.Surname, Sum(tblOrdersItems.Cost) 
AS SumOfCostFROM (tblClientDetails INNER JOIN tblOrders ON tblClientDetails.ClientDetailsID = tblOrders.ClientDetailsID)
INNER JOIN tblOrdersItems ON tblOrders.OrderID = tblOrdersItems.OrderIDWHERE (((tblOrders.OrderDate)>DateAdd('yyyy',-1,Date())))
GROUP BY tblClientDetails.FirstName, tblClientDetails.SurnameORDER BY Sum(tblOrdersItems.Cost) DESC; 

View 5 Replies View Related

General :: Content Of Variable Crashes VBA Code

Jun 16, 2015

I have a form I use to create photo captions. The form has a field where users can edit a pre-generated caption and a field that stores their updates as a final caption in the field "selected_caption".. On my form is a button that runs the code below to check and see if a field ("updated") has been marked true, then copies the content of caption field into the selected_caption field. It works fine 90 percent of the time but for some reason this caption:

LA 109535, LA109535 partial site overview showing blowout with PL's 01- 04. Crew person is excavating a shovel test probe. Photo direction facing southwest. (Roll 31066, Frame 4958)

Results in a missing operator error. I thought it was like a special character thing, so I removed the "'" and the "-". Same error.

Code:
Dim db As Database
Dim rst As Recordset
Dim upcap As String
Dim strSQL As String
Set db = CurrentDb

[Code] .....

View 4 Replies View Related

General :: Enter Single Variable As Criteria For A Query?

Oct 10, 2014

I have a database structure with a series of queries which are all inter-linked.

I want my database to be user friendly, what is the cleanest way to be able to enter a single variable eg as a criteria for a query - say the date, rather than having to change it in a series of queries manually, can I call it from somewhere?

View 8 Replies View Related

General :: Distributed Application - Variable Screen Sizes?

Mar 26, 2013

Is there a means of making an application grow/shrink to accommodate different screen sizes? eg. not all users of a distributed application will necessarily have the same screen size.

View 2 Replies View Related

General :: How To Define Variable In Form As String Which Can Work With Any Event

Jul 16, 2013

I have a form (Datasheet). I need to define some variable in form as string, which can work with any event. E.G in column "A"on event after update, in column "B" on event after update...

I will try to explain with a simple example : form (datasheet) columns: "A", "B"

on event after update in coulmn "A", I could have some like this:
(variable what I need to define) = 3

on event after update in coulmn "B", I could have some like this:
If (variable what I need to define) = 3 then
msgbox "ok"
end if

Now I try to work around the problem and use another column "c" to keep the value from after update A - but I know that, it's bad solution -Right?

View 4 Replies View Related







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