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.
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:
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.
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
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.
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
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!
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.
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.
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?
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.
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
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?
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
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.
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>
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):-
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.
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
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.
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
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
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.