DoCmd.OpenForm Arguments

Jan 24, 2005


I have got an unbound access form, and in this form I gather 2 dates (i.e. through txt fields). Once I have these fields, I want to open a form that has one list box on it. This list box should populate based on the dates that I gather on the previous form. How do I specify this through the DoCmd.OpenForm arguments? Currently I have the following code, but it is not working:

Form 1:
Dim whereClause As String
whereClause = "SELECT * FROM qryInvoice WHERE tblInv.InvDate Between #" & txtStartDate & "# And #" & txtEndDate & "#" & ";"
DoCmd.OpenForm "frmInvoiceFax", acNormal, , , , , whereClause

Form 2:
public Sub Form_Load(args As String)
MsgBox args
lstInvoice.Rowsource = whereClause
End Sub

I know I am not doing it the right way (because it is not working), but I can't actually find how to do it. Help!

View Replies


DoCmd.OpenForm Troubles

Mar 18, 2005

I have a form(frmGetRecord) with a subform(frmSubGetRecord). frmGetRecord has a combobox cmbCNO to choose the patient. The subform displays the admit date and discharge date(if there is one). There can be multiple admit/Discharge dates for a patient. Based on the values from fields on the form and subform, I would like to open a data entry form(frmEvents) for the particular record. I have a command button to run the code to open frmEvents. I am having trouble with the criteria in the where condition.

stLinkCriteria = "[CNo]=" & "'" & Me![cmbCNO] & "'" _
And "[AdmitDate]=" & "#" & Forms![frmGetRecord]![frmSubGetRecord].Form![AdmitDate] & "#" _
And "[DischDate]=" & "#" & Forms![frmGetRecord]![frmSubGetRecord].Form![DischDate] & "#"

DoCmd.OpenForm stDocName, , stQryName, stLinkCriteria, acFormEdit

When I click on the command button I get a type mismatch error. If I test the StLinkCriteria separately, the DoCmd.OpenForm will work for just the CNO field or just the AdmitDate field. If I test those two strings together, I get the type mismatch. Also, DischDate could be blank and I'm not sure how to add an IIf statement to the string to test for that in the where statement. I'm also not sure how to make sure it picks the correct record if there is more than one admit date. I would like to select the desired date record, then have the command button open the appropriate record.

Hope this makes sense. Thanks for any help.

View 10 Replies View Related

DoCmd.OpenForm Fails If Access Is Not The Active Window

Jun 13, 2006

I have an Access 2000 application which, on startup, always launches a 'switchboard' form and sometimes gets information from the user during the startup. Both forms are opened with VBA using DoCmd.OpenForm; the switchboard opens as acNormal and the input form (when used) as acDialog.

Under normal circumstances this works fine.

If, however, the Access window ceases to be the active window in Windows (e.g. the user selects another application's window in the taskbar) the forms do not open (all other VBA code runs correctly).

Any ideas?


View 2 Replies View Related

Pass Arguments To Access

Sep 1, 2005


I want to be able to pass arguments to an access file on start up. I want to be able to grab this value and then perform an action based on this.

The program will send an email with details for a change request, the recipient will then need to click on a link to accept or reject this change. So I want them to be able to click the link which will trigger the program to save accept or reject.


View 3 Replies View Related

Open Form Using 2 Arguments.

Aug 1, 2005

I'm putting together a database of property clients and i have almost finnished but as always i seem to get so very close to the end of a project and i hit a wall.

background:- I have about 5 different tables which mostly have relationships but there is one main table (clientDetails) which holds the main record this has a very predictable clientID primary Key. the other tables have equally predictable keys for the tables ie: LettingID for a letting client insuranceID for insurance clients etc.. the deal is really that EVERYONE is a client so they get the main details filled out and another record in another table using the primary key of the main table in all other tables. one client can have many other records relating to them useing the primary key.

The Problem:- I have made lots of nice forms that all link up together so you can edit and brose all of the records in the database, and this works very well.. however my problem comes when i want to add a new record in one table that relates to the same record in another using the forms not the table view. eg. on form 1 (clientDetails) i add a new client to the database all fine even using the autonum for the PK. now i bring up the record of that client and i have a button (addProperty) this brings up another form (propertyDetails) using the PK from the previous. this works fine if there is already an entry in the DB but if not then the PK is autonumbered..

What i need:- I need to be able to open up a form using PK then (addProperty) button to the next form which finds that record using the pk (clientID) and FK (propertyID) and if there is no FK relating to the PK then to autonumber and use that... so i basically transfer the PK from form 1 to form 2 regarless of any other data relating to it, and auto numbering to the next number in that table for the FK.


form1 form 2
------- > ---------
PK=100 PK=100

this is probibly really basic.. but i hope someone can help ..

Many thanks. = is me..

View 3 Replies View Related


Jan 20, 2007

I'm going nuts here...can you privide some help.

I'm trying to QUERY an ACCESS database called ARQUIVO and i would like to have from the column EMPRESAS all the DISTINCT records that have the same 'aviacao' in the INDUSTRIA column.

and it goes like this:
Code:<%Set rse = Server.CreateObject("ADODB.Recordset")sSQL = "SELECT DISTINCT empresa FROM arquivo WHERE industria='Aviacao'" sSQL,con, adOpenStatic, adLockPessimistic, adCmdText%>

But all I get in a 500 error.

The fact is that if I use "*" instead of "empresa" the query runs but i list all the records with 'aviacao' in INDUSTRIA

I have this SQL query made in ACCESS - that does what I want - but it doesn't rune in mine ASP page.

FROM arquivo
WHERE (((arquivo.INDUSTRIA)="Câmaras Municipais"));

Would anyone help on this?

View 1 Replies View Related

Wrong Number Of Arguments

Jan 8, 2008

Can you help me? I get the error wrong type of arguments in my function as follows
Private Sub Command0_Click()
Call ANewDBWithPass("c:BELest", "secret")
End Sub

Function ANewDBWithPass(ByVal tName As String) '// adds the current date to the name of the database
Dim wsp As Workspace
Dim db2 As Database
Set wsp = DBEngine.Workspaces(0)
If Right(tName, 4) = ".mdb" Then
' Remove .mdb from the name
tName = Left(tName, Len(tName) - 4)
End If
' Add date and extension
tName = tName & Format(Date, "dd-mm-yyyy") & ".mdb"
' Create database
',Set db2 = wsp.CreateDatabase(tName, dbLangGeneral)
Set db2 = wsp.CreateDatabase(tName, dbLangGeneral & ";pwd=" & strPassword)
End Function

View 3 Replies View Related

Modules & VBA :: Run Python Method With Arguments?

Aug 18, 2014

I have a python script "runAll" that takes two arguments: processID (the primary key of one table as a string) and a filename (a full file name path as a string).

Is it possible to run a python method with arguments from inside a VBA script (activated by a button press)?

My python script is called, and the method I want to run is called runAll(processID,filename).

View 4 Replies View Related

General :: Calculate Days Using 2 Arguments

Dec 18, 2012

I have a database to monitor incoming emails from our contractor & my superior wants it to have control like the following situations:

1. If no respond yet, to calculate today's date minus received date
2. If responded, to calculate respond date minus received date

If i use the following expression, it does not relate to if the emails have no respond yet or have been responded.

IIf(IsNull([Reply Date]),DateDiff("d",[Due Date], Now()))

View 4 Replies View Related

VBA Passing Array Arguments To Procedure

May 13, 2015

The procedure call "Call RearrangeCoordinates(RearrangeCoords(), ReturnCoords())" return a message "Type mismatched: Array or user-defined type expected"Are there any views as to why the message is being displayed?

Private Sub CommandButton1_Click()
Dim ReturnCoords As Variant
Dim ...........................................
ArrayLength = UBound(ReturnCoords)


View 2 Replies View Related

Command Line Arguments To Open AND Close Db

Jan 24, 2008

Is there a command line argument to open AND close a db? I am running a schedule task to open a db which has an autoexec macro but I don't want the db to stay open after running the macro. Or is there a close db function in a macro? I see close form but not db.

View 2 Replies View Related

Modules & VBA :: Arguments - How To Pass From Private Sub To Function

Apr 22, 2014

I have a after update event that will match the written record with any exist record in a table in the field "OrgName". If it doesn't find exact match, will call a function with a "soundex" algorithm to see if there is only a misspelling or another name altogether.

In the afterupdate event, I have a string called strOrg (wich is the name I want to compare).

I have the soundex function in a module, so I can use it for several form generally.

What I want is to pass the strOrg to the soundex function, however I don't know how to declare the variables. however I keep having this error:

"compile error: Argument not optional"

and goes to the line tagged as 1 in the private sub afterupdate

The afterupdate sub is the following:


Private Sub tOrgName_AfterUpdate()
Dim strOrg As String
strOrg = Me.tOrgName.value
If IsNull(DLookup("orgID", "torg", "OrgName = '" & strOrg & "'")) Then
resMsg = MsgBox("This organization name is not in the list. If you want to look for similar names press YES, if you want to register a new organization press NO.", vbYesNoCancel, "Organization not found")

[Code] ....

and the soundex function is declared as

Public Function Soundex(strOrg As String) As String
Dim Result As String, c As String * 1
Dim Location As Integer

View 3 Replies View Related

Help With Openform

Oct 19, 2005

I am trying to open a second form that is linked to the first form but i cant get it to work it keeps coming up with a syntex error

DoCmd.OpenForm "frmstudentperformancepoorprevious", , , popUPID = '" & Me.StudentPerformanceID & "'"

Any ideas?? trying everything to get this form to link and everything is failing even the wizard which works if you just enter the record... but if you go back to it later and use the button it brings up a blank record

View 13 Replies View Related


Jan 22, 2006


Im very new with access, and require a little help

what im trying to do is the following

I require a open form button, i can do this with no problems...

When the form opens, i need it to lookup a REP_ID value in a table to see if any records exist for the REP, if there is, i need it to display the form, with details.

If there are no details for REP_ID in the table, i require the form to open just blank, so input can be added!

How do i do this? Do i do it via code, macro?

Any help would be greatly appreciated

View 1 Replies View Related

Modules & VBA :: Date Expression For DCount And Where Open Arguments

Oct 9, 2014

I am getting something wrong but I don't know what - date related.

Take this code for example:

Dim varDate
varDate = Date
If DCount("RunningNumber", "AllocatedVehicles", "ServiceDate=" & varDate) > 0 Then
MsgBox "Go Away", vbOKOnly
Go on and do the real work
End If
End Sub

The DCount line is being completely ignored, no error message, it just cracks on as though there were no records found (but they are definitely there!) I have tried:

Dim varDate
varDate = Date
If DCount("RunningNumber", "AllocatedVehicles", "ServiceDate='" & varDate & "'") > 0 Then
MsgBox "Go Away", vbOKOnly

But that throws up a Type Mismatch (which is what I would expect). Then I tried

Dim varDate
varDate = Date
If DCount("RunningNumber", "AllocatedVehicles", "ServiceDate=#" & varDate & "#") > 0 Then
MsgBox "Go Away", vbOKOnly

And it gets ignored again.

I am having similar trouble trying to open another form using the same field as the open argument, and getting similar results, so it is clearly me that is wrong.

View 7 Replies View Related

Modules & VBA :: DLookup Error - Wrong Number Of Arguments

Jul 1, 2013

Access 2010

I am trying to check for when a user trys to enter a duplicate number.

The control that I am checking is in a subform on the main form:

Main: frmCandidateInfo
Sub: frmTestInfo

Control on the subform is: RankOrder

I am trying to check the control entry against the table entry:

Table: tblTestEvents
Field: RankOrder

Here is what I have:

Private Sub RankOrder_BeforeUpdate(Cancel As Integer)
Dim lngRankDup As Long
lngRankDup = Nz(DLookup("[RankOrder]", "tblTestEvents", "[RankOrder]=" & Forms!frmCandidateInfo!sfTestInfo!Form!RankOrder, 0))
If lngRankDup <> 0 Then
MsgBox TestEventID & " already exists in the database"
End If
End Sub

I know that the error is due to the argument not being correct, but I am not sure how to fix it.

I have tried:

lngRankDup = Nz(DLookup("[RankOrder]", "tblTestEvents", "[RankOrder]=" & Me.RankOrder, 0))

lngRankDup = Nz(DLookup("[RankOrder]", "tblTestEvents", "[RankOrder]=" & [RankOrder], 0))

lngRankDup = Nz(DLookup("[RankOrder]", "tblTestEvents", "[RankOrder]=" & Forms!sfTestInfo!Form!RankOrder, 0))

But nothing seems to work.

View 3 Replies View Related

Openform With Criteria

Nov 8, 2005

I open a form with a criteria set but when the form opens it has every record, rather than restricting the records to those matching the criteria. I wonder if anyone has had this problem before? I use a query in the called to get the underlying recordset.

This is my code:

Dim CritText As String

CritText = "[ID1] = '" & Me.ID1 & "'"
DoCmd.OpenForm "frmTestAll", acFormDS, , stCritText

View 5 Replies View Related

OpenForm Filter

Nov 25, 2005

Hi All,

I have a problem and I can't figure out what I am doing wrong, I have a code:

Private Sub Button4_Click()
Dim compl As String
compl = name1
DoCmd.OpenForm "form1", , , "Field1=" & name1
DoCmd.Close acForm, "form2"
End Sub

Now everytime I click on this button and I enter a value in textbox(name1) it askes for a parameter! This is the only field in the form (form1) where I have this problem by the way. With the other fields it doesn't ask for a parameter. Does anyone know what might be the problem?

View 2 Replies View Related

OpenForm Filter

May 21, 2006

Access 2003
I'm sure this is incredibly simple, but I can't make it work, and can't find an answer in the forums.

:confused: I want to use OPENFORM to open a form showing only the records where a CHECKBOX is checked. I've tried using a query, using WHERE, using the OpenArgs, etc., but I'm clearly not formatting it right.

so... elements are:
btnActiveJobs (command button)
frmJob (form with job records)
chkActive (check box on frmJob that shows whether job is active)

The underlying Jobs table sets the Active field to yes/no

I'd like to do all this in the event code for the button, but I do also have a query (Query1) that produces the right jobs. Including this as the FilterName criterion has no effect.

View 4 Replies View Related

UDFs That Accept Arguments To Process UPDATE/INSERT INTO SQL Stmts?

Mar 17, 2006

Before attempting to create a VBA User Defined Function that will accept arguments for creating UPDATE/INSERT INTO SQL statements, I thought I would check to see if some already exist. It seems like a very tough task to tackle. I'd like it to determine the data type of the the values being placed into the specified fields and subsequently provide the appropriate syntax. (i.e. '" & mString & "', #" & mDate & "#, etc.) Do any exist?

I'm working with MS Access 2003.


Steve G.

View 1 Replies View Related

UDFs That Accept Arguments To Process UPDATE/INSERT INTO SQL Stmts?

Mar 17, 2006

Before attempting to create a VBA User Defined Function that will accept arguments for creating UPDATE/INSERT INTO SQL statements, I thought I would check to see if some already exist. It seems like a very tough task to tackle. I'd like it to determine the data type of the the values being placed into the specified fields and subsequently provide the appropriate syntax. (i.e. '" & mString & "', #" & mDate & "#, etc.) Do any exist?

I'm working with MS Access 2003.


Steve G.

View 1 Replies View Related

The OpenForm Action Was Cancelled

Aug 23, 2005

I am trying to open a form with a specified record using double clicked event (list box) but access is throwin "The OpenForm action was cancelled". My code is:

Private Sub lstSchool_DblClick(Cancel As Integer)
Dim test As String
Dim thisForm As String

thisForm = "frmRegister"
test = "ID = " & "'" & lstSchool & "'"

DoCmd.OpenForm thisForm, , , test

End Sub

ID is a AutoNumber field. I have used this code in my other dbz and it works fine ....

View 12 Replies View Related

Openform At Specific Record (again)

May 9, 2006

Sorry about this. I know there is loads on here about this but I just can't get it to work.

I have a basic table of dates.
One form based on the dates via a query

When the form opens, I want it to show today's date but allowing access to all the other date records (so no filter).

Any help please

View 14 Replies View Related

Passing Variables In An OpenForm Method

Dec 8, 2005

I can't seem to get the following code to work.
Any help would be appreciated:

Public Function NonConform(strProduct, strBatch As String)

On Error GoTo HandleErr
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmProductNonConforming"
stLinkCriteria = "[ProductName]=" & "'" & strProduct & "'"
stLinkCriteria = stLinkCriteria & "AND [BatchNum]=" & "'" & strBatch & "'"
DoCmd.OpenForm stDocName, , , (stLinkCriteria)
MsgBox "Error in NonConform Function : " & Err.Description
Resume Next
End Function

View 1 Replies View Related

Access VBA: OpenForm To A Specific Record

Dec 26, 2006

I am not a specialist, but am trying to create an application with Access 2000to manage our company’s orders. I have a table called ‘Service’ containing descriptive data on the type of service requested. This table is linked to several other tables, with ‘ServiceNo’ as the primary key linking most of them. The service number is not an autonumber, but a counter incremented through code, for specific reasons that I won’t develop here.

I have created two forms: one to consult all the service records (F_Service_Consult), with a button to open another form that allows the user to add a new service record (F_Service_Add).

When the new service form opens, the service number counter is incremented and this number is assigned as the new 'ServiceNo' in a new record added to the ‘Service’ table (using the SQL ‘Insert’ command). I would like this form (F_Service_Add) to open on this record only. In the code that creates ‘ServiceNo’, the correct value is contained in a variable called ‘lngServiceCount’. I have tried using this code to open my form:

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "F_Service_Add"
stLinkCriteria = "Forms![F_Service_Add]![ServiceNo]='" & lngServiceCount & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

When I run the code step-by-step, the correct value is shown for ‘lngServiceCount’ when the mouse hovers over the variable (for ex. ‘155’). When the form opens, I have 1 record (Filtered), but nothing shows in the ‘ServiceNo’ text box.

I have deactivated the code that is in the ‘OnCurrent’ event procedure of this form to avoid any interference.

There are many sub-forms on the main form, which also contain the ‘ServiceNo’ in text boxes.

When I use this command to open the form:

DoCmd.GoToRecord , , acLast

the form opens correctly, with the correct ‘ServiceNo’, but ALL the records are opened.

The variable type for ‘lngServiceCount’ is a long integer. (I hope that is the correct term in English, because I am using a French version of Access).

I would be very grateful if anyone could tell me what I’m doing wrong. I’ve tried to be clear, but if more information is required, I would of course provide what’s missing.
Thanks in advance.

View 4 Replies View Related

Where Condition Of OpenForm Command Not Working

Jan 19, 2005

The scenario is... also apologies if this seems a lot. Simple really.

An edit button on a subform is to open a separate form for editing, and I obviously want to apply a where condition to display the relevant record. So I have

DoCmd.OpenForm "editReviewPEST", acNormal, , ReviewID=Me.ReviewID, acFormEdit, acWindowNormal, False

The Record Source for editReviewPEST uses an INNER JOIN...

SELECT Reviews.Year, Reviews.ReviewID, Reviews.LesseeID, Lessee.DateOfOrigSanction, Reviews.Exposure, Reviews.ExpoCurrency, Reviews.SentToCredit, Reviews.Approved, Reviews.Completed, Reviews.Comments, Reviews.LevelOfLastSanction, Reviews.CreditManager, Reviews.TypeOfReview, Reviews.DateOfLastCreditReview, Reviews.DateOfNextCreditReview FROM Lessee INNER JOIN Reviews ON Lessee.LesseeID = Reviews.LesseeID WHERE (((Reviews.LesseeID)=[Forms]![Reviews]![SelectLessee])) ORDER BY Reviews.ReviewID DESC;

So I get the form to open with all the records relvant to the lessee, but to filter it further to exact ReviewID, I thought I could include ReviewID=Me.ReviewID (an Autonumber PK) as the Where Condition to the DoCmd.OpenForm. Instead I get a form which looks like Add Record Form.

View 4 Replies View Related

Copyrights 2005-15, All rights reserved