Code In Modules

Aug 25, 2006

Friends,
I need to place a vba code from a regular event in a form to a module so that when the form opens the function in the module is recalled using a macro.
How do I do this?

For example, I have the following code in the OnOpen event of a form:

Dim strInputBox As String, bytChoice As Byte
InputPoint:
strInputBox = InputBox("Please input the password.", "Password Required - Restricted Area! ")
If Len(strInputBox) > 0 Then
If strInputBox <> "***" Then
bytChoice = MsgBox("Wrong password" & vbNewLine & vbNewLine & "Do you want to try another?", vbExclamation + vbYesNo, "Warning")
If bytChoice = vbYes Then
GoTo InputPoint
End If
Else
DoCmd.OpenForm "Maintenance"
End If
End If

I would now like to place this code in a module and run it using a macro.

Any help? Thanks.

View Replies


ADVERTISEMENT

Modules & VBA :: Scrolling With Code

Dec 13, 2013

I have a form (frmCommoditySupplierSpend)and a subform (frmCommoditySupplierSpendSubForm1ByVend). I have a control button in the main form that will scroll down the page of the main form to a point I desire by using:

Forms![frmCommoditySupplierSpend].GoToPage 1, 0, 9250

The problem that I am having is in my subform I have a button as well and when a user clicks the button in the subform I want the main form to scroll down to the same point. I thought the same exact code should work, but it ends up scrolling down the subform instead of the mainform, even though the main form is being stated. how to scroll down my main form when using a contol in subform.

View 2 Replies View Related

Modules & VBA :: Code To Take To A Duplicate Record

Aug 13, 2013

I have a form based on a query and have written code to display a msgbox if a duplicate entry is inputted in the NHS_Number field in the form. I have also added code "me.undo" to clear the form so that it is not saved. I am looking for a piece of code that will display the duplicate record. Here is my code thus far:

Private Sub NHs_Number_BeforeUpdate(Cancel As Integer)
Dim dbs As Database
Dim rst As DAO.Recordset
Dim x As Integer

[Code]....

View 4 Replies View Related

Modules & VBA :: Generate Scannable Bar Code

Jul 23, 2014

I is it possible to generate a bar-code that which is a path to a file name on my server from access 2010? if so here is what i would like to do:

- for each expense i enter in my application i'd like to generate and print a bar-code

- scan bar-code on copy machine (which is path and file name of document to be scanned)

- scan my expense receipt (copy machine now knows where to send the receipt and how to name the file ala the bar-code that was scanned)

I'm not sure if this is at all possible using only access and vba.

View 2 Replies View Related

Modules & VBA :: Excel Referencing In Code

Nov 19, 2014

I have recently upgraded to Access 2013 and this has updated all my object library references to 15.0. The problem is that my colleages are still using Access 2010 and when they try to use the database they are receiving a missing reference error.

I have removed the Excel reference but this gives me the 'object type not recognized' error when running the code.I have tried to download the 14.0 reference libraries in order to add them back in but for some reason the installer doesn't work.

View 3 Replies View Related

Modules & VBA :: Use String To Call Code?

Sep 12, 2014

I am trying to use a textbox value to call vba code and can not get it to work.

I keep getting an error on the call str1 line.

Code:

Sub formscript()
Dim str1 As String
str1 = [Forms]![fscripts2]![t3]
'MsgBox str1
If str1 = "" Then
str1 = "err1"
Exit Sub
Else
Call str1 ' this is where it call the script based on value in textbox
End If
End Sub

View 14 Replies View Related

Modules & VBA :: SQL Code Return Value And Set To Variable?

Sep 4, 2013

Code:
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
Dim SQLstr As String

[Code]....

I created this about 1 hour ago but my laptop crashed and didnt save. So, I open a record set and rs is now loaded with the record I want,

how do I assign the value of "Status" as a vba variable. when I try StatusInt = rs I get the "Type Mismatch" error...

View 4 Replies View Related

Modules & VBA :: Automated Caps In Code?

Jun 3, 2015

I am having a few issues with my module code in Access 2002. for some reason every time I write some code Access is automatically making the first letter a capital so for instance [Our Ref] should be [Our ref] but it simply will not let me do it!

Temp = rstHTML!html1 & rstProp![Our Ref] & rstHTML!html2 & rstProp![Our Ref] & rstHTML!html3 & rstProp![Property Title]

View 6 Replies View Related

Modules & VBA :: Select List Box Value By Code

Jun 11, 2013

it has a listbox, wich RowSource is a query with 5 fields, BoundColumn is field#1.I have a comboBox with values of field#1 to have an 'AfterUpdate' Event, that highlights the row in the listBox that has the value of the comboBox in in field#1.

View 1 Replies View Related

Modules & VBA :: Run Code When Pressing Enter

Dec 5, 2013

I want to run some code when a user presses the Enter key on a form - how do I do this?

View 3 Replies View Related

Modules & VBA :: Zip Code Not Importing With Extension

Jun 27, 2014

I have a pretty basic TransferSpreadsheet module that works well except that if the Zip code has the four digit extension, it's not importing.

Option Compare Database

Dim myCheck
Function MeridianLinkFileImport()
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tbl_MeridianLinkFileImport", "R:DEPT-BRCONSUMER LENDINGMarketing Campaigns2014 Auto Loan PrescreenReport from LoansPQ.xls", True, "Sheet1!A3:AO50000"
End Function

If there is no extention, it is importing fine... 85086 works fine but 85018-4710 doesn't import.

The field is a Short Text data type.

View 3 Replies View Related

Modules & VBA :: Code To Return Field Name Rather Than Value

Apr 17, 2014

I have a code that finds the first, second, and third minimum value in a row across the fields. Now, I am trying to find a code to look at these values, find the field it is located, and return the field name. I tried several variations of my code to return the field name rather than the value, but have been unsuccessful to this point.

Function NthMinimum(intPosition As Integer, ParamArray FieldArray() As Variant) As Variant
Dim varTempArray() As Variant, varTempValue As Variant, intArrayValues As Integer
Dim I As Integer, J As Integer
ReDim varTempArray(UBound(FieldArray))
intArrayValues = 0

[Code] ....

As you can see, this works to find these values while ignoring NULLS. How to return the field name?

View 1 Replies View Related

Modules & VBA :: Run Two Sets Of Code On (Before Update)

Aug 30, 2013

I have a set of code to keep an audit trail that calls a module:

Code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Call AuditTrail(Me, CurrentCYIDPK)
End Sub

Calls

Code:

Option Compare Database

Const cDQ As String = """"
Sub AuditTrail(frm As Form, recordid As Control)
'Track changes to data.
'recordid identifies the pk field's corresponding
'control in frm, in order to id record.
Dim ctl As Control
Dim varBefore As Variant

[code]....

how to run both of these events on Form_BeforeUpdate.

View 11 Replies View Related

Modules & VBA :: Input From Form Into Code?

Jan 20, 2014

i have being requested to create a from that displays the number of files in different folders. I can accomplish this somewhat with the code below. In the example below it is only showing the code for the first 3 folders. I have 7 folders in total to count.

1.Each week the location of the data will change. In the example below it is showing 2014-W03, the following week it will be 2014-W04 etc. etc. I was thinking of having an input box in the form that the user type the date into, to trigger the code, but how would I go about changing the code to include this variable?

2.I need to repeat this code for 9 other products, so my form will be displaying data for 10 products in total. I know I could copy this code 9 times and modify it accordingly, but is it possible to loop it in some way?

Code:
' Returns the total number of fails
Private Sub Form_Load()
Dim file As Object
Dim fileCount As Long
With CreateObject("Scripting.FileSystemObject").getfolder(" estmachineProduct1 FAILS2014-W03")
For Each file In .Files

[code].....

View 11 Replies View Related

Modules & VBA :: Lock Down A Field Through Code?

Jun 7, 2013

I have a field within a form that needs to be modified based off of someone's access level and I have written that part but not sure how to keep others from modifying the field.

Code:
Private Sub Qty_Rcvd_Click()
If ap_GetUserName() = "Danny_Davis" Or ap_GetUserName() = "christopher_ayers" Or ap_GetUserName() = "Tena_McCrackin" Then
GoTo 10
Else
MsgBox "You are not authorized to view this form"
End If
10
End Sub

Right now this code will bring up the msgbox for someone not authorized but once they hit "ok" the msgbox goes away and they can still change the field. What can I type in here to lock down the field for someone not authorized?

View 3 Replies View Related

Modules & VBA :: Creating Msg Box That Runs A Code

May 29, 2014

I have a little problem in creating a msg box that then activate a code. How can I do? I was doing

Private Sub Chiusura_Pratica_Click()
MsgBox "Bla Bla Bla " _
VbMsgBoxStyle.vbYesNo
If Response = vbYes Then
Me.Stato.Value = "A Scadere"
Me.Assegnato_a.Value = ""
Else
MyString = "No"
End If
End Sub

But it doesn't work...

View 3 Replies View Related

Modules & VBA :: Code That Populate Field

Feb 25, 2014

I am using MS Access 2010 and I am struggling to write some vba in my database. On my form, I have a Payment Type dropdown field.When someone selects a payment type I want the code to calculate the end date. Then populate the End Date field with the answer.I will be having a few payment types too, but for now on the dropdown I have two.2/Month and 24/Annum.

View 3 Replies View Related

Modules & VBA :: Trying To Code INSERT INTO Table

Nov 11, 2014

I have a form that is calling data from a table. Then the user can determine if they approve the question or not. So what I am trying to do is take one combo box that has yes or no and write it to the database. I thought I had it correct, but appears I do not as it is not writing yes or no to the table. The field initially has no value and that is my query for calling the data for the user to select from. Here is the code that I have so far

<code>
'add approval to yes
CurrentDb.Execute "INSERT INTO travelerQA(approval)" & _
" VALUES('" & Me.cmbapproveda & "')"
</code>

View 5 Replies View Related

Modules & VBA :: Define Current Sub Folder Within Code?

Oct 9, 2014

I am trying to define a path to identify a current folder - I'll try and explain the way the following code works first (and it does work 100%)

The following code identifies folders and sub-folder structures and imports them (their structures and folder paths and filenames) into a DB

It also simultaneously retrieve's any xml docs within those respective folders and imports the XML data into the same database ........ and then moves those folders into a "processing folder" location.

Cool yes, but I can only import the XML doc's at the moment, by hard coding the path (like this):-

path = "C:UsersjeremybDesktopsnapmadXYZ123XYZFILES 0061940"

The code is highlighted as above - in the FULL code below:

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Code Begins:-
Option Compare Database
Option Explicit

[Code]....

View 2 Replies View Related

Modules & VBA :: Suspending Code Until Outside Application Finished

Nov 5, 2014

I have a Subroutine that is using CutePDF writer to create a PDF from a report, then attach it to a new message in outlook. The problem is the code runs too fast and it's looking for the file to attach before the file is created.

I'm getting
Run-time error '-2147024894 (80070002)':
Cannot find this file. Verify the path and file name are correct.

Yes, I know why I am getting the error, and yes I could use a loop timer, except it may be 5 seconds before the person finally clicks OK in CutePDF dialogue box, it may be 5 minutes or it may be 5 hours.

View 8 Replies View Related

Modules & VBA :: Adding Another Parameter To Code For Report?

Dec 5, 2013

I am trying to add another parameter to a report to only get those specific records. I did not write the code and am very confused on how it works. Right now it is getting records in the Access database between the 2 dates entered. But NOW I need to add a parameter to select only records between those dates AND with the AccountNumber LIKE acctltr (this is the field from the form). They can either put in an "X" or an "P X". The AccountNumber needs to end in which ever one they enter.

Here is the code that is currently existing and supposedly works. At least it gets all the records between the dates even tho it still prints records with a ZERO balance.

Code:
Private Sub cmdprint_Click()
On Error GoTo exit_cmdprint
'mysql = "SELECT * from InvoiceTable " & _
' " WHERE ((not InvoiceTable.InvoicePrintDate1 Is Null) AND (not InvoiceTable.InvoicePrintDate2 Is Null) AND (InvoiceTable.InvoicePrintDate3 Is Null) AND (InvoiceTable.InvoiceDate Between #" & dtefrom & "# And #" & dteto & "#))"
'Me.RecordSource = mysql

[code]...

View 5 Replies View Related

Modules & VBA :: Creating A Small Loop To Run Code

Oct 1, 2013

creating a small loop to run code.For each record from AREA with PLANTPROGRAMID = VARIABLE Then...In this example, my table is called Area, my field is called plantprogramid, and my variable is defined earlier in code.

View 5 Replies View Related

Modules & VBA :: Getting Code For Conditional Default Field Value?

Jan 17, 2014

convert the following into VBA code for an Access 2007 field on a form. It is needed to create a conditional default value based on another field's category: (Note: TransType, MembershipYear and Dues are field names and are all on the form). Based on the TransType (which is really a category of membership) I want the Dues field to have the applicable default value automatically entered.

For MembershipYear > 2008
If TransType="Individual" or TransType="I" Dues=35.00
If TransType="Family" or TransType="F" Dues=50.00
If TransType="Founder" Dues=100.00
If TransType="Student" Dues=10.00
If TransType="Lifetime" Dues="" or is Null
If (TransType is Null or TransType="") and TotalPaid >0, Dues=35.00

View 3 Replies View Related

Modules & VBA :: Code Doesn't Wants To Set The Control Default Value

Aug 7, 2013

code doesn't wants to set the control default value

View 5 Replies View Related

Modules & VBA :: Add Multiple Recipients To Email Code?

Sep 18, 2013

How do I add multiple recipients to the '.To' line in the code below?

Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
.BodyFormat = olFormatRichText
If Me.txtDepartment = "IT" Then
.To = "my email"
End If
.Subject = "hi"
.HTMLBody = "hi"
.send
End With

View 3 Replies View Related

Modules & VBA :: Code For Specific Lookup Selected

Jul 17, 2013

An if statement which will disable out a field depending on which type of field is selected from a separate lookup.I know that is confusing, so let me explain with an example. If I have a lookup field connected to "Vegetables", "Fruits" and "Nuts". If the user selects a "Vegetable" from the lookup field, I need another field disabled, for example sake, "What fruit did you buy?". If the user selected a "Fruit" from the lookup, "What fruit did you buy?" would be enabled.

I know how to enable and disable fields, but it is the If Statement. How would you specify an If statement to specifically look at which category of a lookup is selected?The lookup is not static. So going with our example, the user can add more fruits, vegetables, and nuts as desired, so simply specifying the IDs for the available options will not work. The If statement needs to encompass the category.

View 4 Replies View Related







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