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 Replies
ADVERTISEMENT
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
Oscar
View 14 Replies
View Related
Aug 24, 2006
Hello, fantastic site you have here!
I have a form based on a table called TermWithPaysStoredData that shows a single row for everyone in the table with a small amount of info from the table and has controls for a user to enter dates which writes to that same table.
I have a subform that reads that same table but has much more information about each row. I would like to add a button to each row of the main form that says "More Info". When clicked, it should open the subform to the same employee.
The field I want to match is called ID. My main form is called fTermWithPays and my subform is called fTermWithPaysMoreInformation.
I tried using the OpenForm method but that either opens the form to the first record or filters and shows only one blank record.
I'd like to use a macro for this if possible because I don't know VB.
Any ideas? Let me know if more explanation is needed.
Thanks very much!
View 2 Replies
View Related
Oct 19, 2005
Hi All
I'm currently working on a product catalogue, i have a product data screen (frmProductLookup) one of the field s i have is "Replacement" for when a product is superseeded. What i want to achieve is to be able to click on a button and open a second product data screen that automatically goes to the record for the replacement product.
I've currently tried creating a duplicate data form (frmProductLookup2) and used the openform wizard, but for some reason this pulls up a blank record...any ideas
cheers.
View 3 Replies
View Related
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?
Simon
View 2 Replies
View Related
Aug 5, 2013
I'm working with an old database and I am getting this error. I have have access 2010. I starting to receive this error after I unlinked one of the tables.
Private Sub Command9_Click()
On Error GoTo Err_Command9_Click
Dim stDocName As String
Dim stLinkCriteria As String
[Code] ....
View 3 Replies
View Related
Jan 11, 2014
I have 2 Tables. Table "BOL" and Table "Containers". Both contain "Job_Number" and "Bill_of_Lading_Number" as a field. I would like to get a "Bill_of_Lading_Number" record from "BOL" and add it to "Bill_of_Lading_Number" in "Containers" table based on condition when both "Job_Number" are equal. I have tried two methods. One with DLookup and another with SELECT. Both work but with a small problem.
When I execute them, a dialogue box popup asking me to enter the "Bill_of_Lading_Number" value while the required value shows as dialogue box heading. This box shouldn't come up and I am not sure why this is happening. "varsJobCont" variable I get from another form and is "Job_Number" value that determines the record to be selected.
My Both Codes are:
Dim strBill As String
strBill = DLookup("Bill_of_Lading_Number", "BOL", "Job_Number = " & Application.TempVars("varsJobCont").Value)
DoCmd.RunSQL "Update Containers SET Bill_of_Lading_Number = " & strBill & " WHERE Job_Number = " & Application.TempVars("varsJobCont").Value
Dim strBill As String
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
[code]....
shows the dialogue box and the heading "bbb1055" is actually the correct value I needed to get. It should have been put in the other table automatically without the need to insert it manually again.
View 13 Replies
View Related
Jul 23, 2013
I want to hyperlink from a query direct to the relevant record in a specific form. I have a hyperlink field in the form which shows up in the query. When clicked in the query, this hyperlinks to the form but I cannot make it select the correct record in the form.How do I get it to select the correct record?
View 3 Replies
View Related
Oct 3, 2005
Hello, I have just spent ages doing searches and reading everything I can on locking. But, I have yet to find an answer as to how I can lock a specific field in a specific record.
e.g. Staff enter customer details, then at the end of the day the admin (me) checks it over and presses a big old button that stops them from locking certain fields in the current record only - they must still have access to the unlocked fields of the current record, and it must not lock any other records.
I'm guessing there's some VB code in the form of fieldname.lock = true, but then it locks the field throughout the whole table!
Can anyone tell me how to do this please?
View 11 Replies
View Related
Jul 9, 2015
I am new to access i have a problem which is i have made a form which contains a subform and a read only subreport, what i want is the ability to select a record in read only subreport as in the picture attached and make a button that when i press on it, it should copy the values of the itemsID field, Packing field, ContainerNo field and origin field from the selected record and then paste them in the subform below.
Also i want to add more then one item, so the when i press on another record it should paste the values below the first record.
View 12 Replies
View Related
Nov 8, 2013
I have a continuous form for which the recordsource is a query that retrieves dates from 10 days in the past to 10 days in the present. I want the record with today's date to be at the top of the form. The record with the oldest date is always on top. Is this a scrolling issue? How can I get the record with today's date to appear on top?
View 5 Replies
View Related
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
Hello,
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
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
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
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
Jan 24, 2005
Hi,
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 2 Replies
View Related
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
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
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)
HandleErr:
MsgBox "Error in NonConform Function : " & Err.Description
Resume Next
End Function
View 1 Replies
View Related
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
Apr 4, 2015
I have a form that opens when you initially open the MS Access file...
This first form posts session and user ID data to a sessions table, then closes itself and opens an end user form (i.e. the main form in the application)
It's work just fine for many weeks, up until a few minutes ago. Now, when I open the MS Access file I get this error message:
Run-time error '2501':
The OpenForm action was canceled.
When I choose "debug" from the error message, it's showing me that the error happens here:
Code:
Public Sub CloseMeAndOpenMain(frmMe As Form)
DoCmd.Close acForm, frmMe.Name
DoCmd.OpenForm "0100_0000_STRAT_AND_REQ_ASSEMBLY_ECs_LISTING"
End Sub
The thing is, I can then walk through the code with no issues (i.e. when I hit F8, it runs...)
Also when I open the first "sessions" form from inside MS Access (as opposed the file open feature) it runs just fine and opens the main end user file without any issue.
I only get the error when I initially open the first form from the file...
View 1 Replies
View Related
Mar 20, 2015
I currently have 3 forms open and when I call a specific function and it gets to this line below it goes to the on close of 1 of my open forms closes that form before it opens the selected form in code (below) in design mode. It doesn't close all my forms....why does it do this?
DoCmd.OpenForm formname:=dynform, View:=acDesign, WindowMode:=acHidden
View 5 Replies
View Related
Aug 23, 2013
I am creating a search function to search a name. The DB stores it as [First Name] , [Last Name].... This query works
Code:
SELECT *
FROM tblVolunteers
WHERE ((([First Name] & " " & [Last Name]) Like "*bob j*"));
It will show me records for Bob Johnson, Bob James and Bob Jones....
I am trying to duplicate this with a DoCmd.OpenForm statement... Replacing the static name with a field variable...
Code:
Dim whereClause As String
whereClause = "[First Name]" & " " & "[Last Name] Like " '*" & volunteerName & "'*""
DoCmd.OpenForm "Volunteers", acNormal, , whereClause, , , False
View 4 Replies
View Related
Mar 3, 2005
Hi,
Does anyone know some code that will take me to the record whose field "A" has value "B"?
It sounds very simple but I can't find anything the does it!
Basically I have a table or enquiry records, some of which are related. I just want to be able to click on a button to take the user straight to the related record. The current design does this using a filter but this is pretty rubbish as it meanhs that in order to search on all records I need to select all records again first.
View 1 Replies
View Related
Sep 29, 2005
The following is a function in my Form "Enter"
--------------------------------------------------------------------------
Private Sub PoNum()
Dim strForm As String
Dim strwhere As String
strForm = "GoodOne"
strwhere = "[Forms]![GoodOne]![Orders3].[Form]![PO_Num] ='" & txtPO & "'"
If [txtPO] <> "" Then
If DCount("[Po_Num]", "Orders", "[PO_Num] ='" & txtPO & "'") = 0 Then
MsgBox "Sorry, No record matched"
txtPO.SetFocus
Else
MsgBox "yes"
DoCmd.Close acForm, "frmPopUp"
DoCmd.OpenForm FormName:=strForm, wherecondition:=strwhere
End If
End If
End Sub
------------------------------------------------------------------------
"Orders3" is the subform of Form "GoodOne" .
When the user enter the PO Number in txtPo, and press "ok" , it will go to
that record.
BUT it just show a new blank reocrd instead.
What's wrong with the programme ??? (is it the matter of subform ?)
Thanks
View 3 Replies
View Related