Hi all, I have a form called frmrgstr with three text boxes, one combo box, and one button. Also, I have a table called info with four columns. That form "frmrgstr" is not based on any table. What I want is, that to send data from the form to the table after clicking the button for the form.
I did the required code:
Dim x As String x = "INSERT INTO info(UserName, PassWord, Email, Gender) VALUES(Me.Text0, Me.Text2, Me.Text4, Me.Combo29)"
UserName = Me.Text0.Value Me.Text0.SetFocus
Password = Me.Text2.Value Me.Text2.SetFocus
Email = Me.Text4.Value Me.Text4.SetFocus
Gender = Me.Combo29.Value Me.Combo29.SetFocus
DoCmd.RunSQL x MsgBox "Welcome! " & Me.Text0
But after running the code, each time it will ask me about the value of text0, text2, text4, and combo29. So please, what is wrong with that code......????? See the attached file.
The following code is for a delete button that is supposed to delete a job. However, in order to delete a job, related records (in tblJobDetails and tblLaborDetails) need to be deleted first. What I did was try to open the record source and delete them, and then once they're all deleted, delete the job. When I click the button, though, no action is taken and I get the error message:
The record cannot be deleted or changed because table 'tblJobDetails' (or tblLaborDetails if tblJobDetails is empty) includes related records.
Is there any way to get this code to work without making the relationships cascade delete?
Thanks a lot
-Jason
Code: Private Sub cmdDeleteJob_Click()On Error GoTo Err_cmdDeleteJob_ClickDim dbRoofing As DAO.DatabaseDim rcdJobDetails As DAO.RecordsetDim intJobID As IntegerDim intMaterialID As IntegerSet dbRoofing = CurrentDbintJobID = Me!JobID'clear out materialsSet rcdJobDetails = dbRoofing.OpenRecordset("tblJobDetails")rcdJobDetails.FindFirst "JobID =" & intJobIDIf rcdJobDetails.NoMatch = False ThenDoDoCmd.DoMenuItem acFormBar, acEditMenu, 9, , acMenuVer70DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70rcdJobDetails.FindNext "JobID =" & intJobIDLoop Until rcdJobDetails.NoMatch = TrueEnd If'clear out laborDim rcdLaborDetails As DAO.RecordsetDim intServiceID As IntegerSet rcdLaborDetails = dbRoofing.OpenRecordset("tblLaborDetails")rcdLaborDetails.FindFirst "JobID =" & intJobIDIf rcdLaborDetails.NoMatch = False ThenDoDoCmd.DoMenuItem acFormBar, acEditMenu, 9, , acMenuVer70DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70rcdLaborDetails.FindNext "JobID =" & intJobIDLoop Until rcdLaborDetails.NoMatch = TrueEnd If'delete jobDoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70Exit_cmdDeleteJob_Click:Exit SubErr_cmdDeleteJob_Click:MsgBox Err.DescriptionResume Exit_cmdDeleteJob_ClickEnd Sub
I'm new to MS Access but I'm trying to do subcontractors database for my company. I've got a menu form with to listboxes on it. First listbox is a subcontractor name if I choose the name the second list box will show me the names of the emplyess attached to this subcontractor. Second form is subcontractor details with emplyees subform. If I will dblclick subcontractor listbox it takes me to record with subcontractor but I can't figuret out how to do that if I dblclick the employee listbox it will take me to appropriet subcontractor detail and to wright employee details. PLEASE HELP ME. I'm strugling with this. Thanks
I've made it to set focus to subform, but if I will choose a subcontractor from the first listbox and dblclick on lstEmployee it is choose wrong record of the employee. Have somebody have an idea what I'm doing wrong
I don't know how to attach the file,can sombody tell me how.
Code of this listbox:
Private Sub lstEmployee_DblClick(Cancel As Integer) DoCmd.OpenForm "Subcontractors", acNormal, "", "", , acNormal DoCmd.GoToRecord , , acGoTo, Forms!Menu!lstSubcontractor Forms!Subcontractors!tblEmployeesubform.SetFocus Forms!Subcontractors!tblEmployeesubform.Form.Emplo yeeID.SetFocus DoCmd.GoToRecord , , acGoTo, Forms!Menu.Form!lstEmployee End Sub
I think last line makes me those troubles but I don't have an idea what is wrong.
So I created a search form which filters my results. Apparently I don't have enough posts to link to the source of the code though. The code is from this website, /forums/showthread.php?t=188663
I then wanted to allow users to double click a result in the listbox to take them to the form which contains details about that record, however the listbox doesn't point to the correct record.
-When nothing is specified in the search field, all records are shown in the listbox, but double clicking on the first record takes me to a form that has no information. Clicking the second record takes me to the Detail Form of the first record. -When information is put into the search field, the results are filtered and only a few display, however clicking the first result again takes me to a blank form while the second result takes me to the first record of the unfiltered list. There is no way to reach the Detail Form for the last result of the listbox. -I tried right clicking the results in the listbox and copy pasting the information. The first result gave me a "0", the second a "1", and so on and so forth. This was the same whether or not the information was filtered or not. -I tried switching to a combo box and got the same results.
I have a form "frmMAINEntry" with a tabcontrol with several pages. The form's Record Source is a query "qryMainData"; however, on two of the pages there's a difference. On the page "Program List" I have a listbox that has a Row Source to table "tsubProgramList" and on the page "Program Details" I have a subform that's Record Source is also "tsubProgramList". The two pages of the tabcontrol are: "ctlProgramDetails" and "ctlProgramList".
The table tsubProgramList contains these fields: ProgramID..............AutoNumber Program Description...Text Facility...................Text ProgramCoordinator...Text
I'm trying to develop code that will allow me to doubleclick on an item in the listbox which will change tab pages and display the selected record in the subform that's on the other tab page. See code below:
Code: ================================================= Private Sub lstPrograms_DblClick(Cancel As Integer) Dim rs As Object Dim db As Database Set db = CurrentDb() Set rs = Forms![frmMainEntry]![fctlProgramList].Form.Recordset.Clone rs.FindFirst "[ProgramID]" = " & Str(Nz(Me![lstPrograms], 0))" If Not rs.EOF Then Forms![frmMainEntry]![fctlProgramList].Form.Bookmark = rs.Bookmark Me![ctlProgramDetails].SetFocus Call HideNavButtons End Sub ================================================= Someone's help would be greatly appreciated.
I used one of the listbox search functions from the forums and changed it a bit to suit my needs.
I'm not having any errors in the code but I'm not getting any results in my listbox after I search. Also, when I type in what I'm searching for the letters always start in the left so i ended up spelling my words backwards.
This is what I have:
Private blnSpaceBar As Boolean Option Compare Database Option Explicit Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 32 Then blnSpaceBar = True
End Sub
Private Sub Form_Load() On Error Resume Next SetListDefaultRowSource
Me.txtFilter.Enabled = True Me.txtFilter = "" DoCmd.GoToControl "txtFilter" End Sub
Private Sub ComboParent_AfterUpdate() Me.ComboChild.Requery End Sub
Private Sub ComboChild_AfterUpdate() Me.LstFindings.Requery End Sub
Private Sub txtFilter_Change() If IsNull(Me.txtFilter) Then SetListDefaultRowSource Exit Sub Else If blnSpaceBar = True Then Me.txtFilter = Me.txtFilter & " " blnSpaceBar = False End If Me.txtFilter.SelStart = Len(Me.txtFilter) End If End Sub
I have adapted code from ghudson's example on 'http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=52736
I have a subform called frmsJobPartsUsed, which contains a multiselect list box where the user can select multiply parts used for one job and click a save button, which saves the parts to rows on the same forms (see picture). The user then enters the number used and that number is taken away from the UnitsInStock. This form is made up of the following two tables; TblStore PartNo PartName UnitsInStock ReOrderLevel Discountinued Remark
The multiselect listbox is made form tblStore, PartNo, PartName and Discontinued = 0
This all works fine so far.
What is need to do is before the parts selected are saved to the table I want to run some code to check If a part’s UnitsInStock is equal to 0 then Message box saying no stock left need to reorder. It won’t save it to the table. Or else If UnitsInStock is greater than 0 but less than or equal to ReOrderLevel Message box saying Stock running low need to reorder asap.
I have this kind of working but it doesn’t seem to be finding the correct UnitsInStock for the part selected. Here is the code;
Private Sub cmdAnswer_Click() 'SAVE BUTTON On Error GoTo ErrMsg:
'Code adapted from ghudson's example on 'http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=52736
Dim myFrm As Form, myCtl As Control Dim mySelection As Variant Dim iSelected, iCount As Long
Dim myDB As DAO.Database Dim myRst As DAO.Recordset Dim myRstCount As DAO.Recordset
Set myDB = CurrentDb() Set myRst = myDB.OpenRecordset("tblPartsUsed")
Set myFrm = Me Set myCtl = Me.lstAnswers
iCount = 0 'Count number of selected records/items For Each mySelection In myCtl.ItemsSelected iCount = iCount + 1 Next mySelection
'Check if anything is slected If iCount = 0 Then MsgBox "There are no Parts selected..", _ vbInformation, "Nothing selected!"
For Each mySelection In myCtl.ItemsSelected If Me.UnitsInStock.Value = 0 Then MsgBox "Out of Stock!" & Chr(13) & "Please returen to Orders or Store to Re-Order Stock. " & Chr(13) & " ", vbOKOnly + vbCritical, "Re-Order Stock" myCtl.Selected(mySelection) = False
Else If Me.UnitsInStock.Value > 0 And Me.UnitsInStock <= Me.ReOrderLevel.Value Then MsgBox "The Store is running low on stock!!" & Chr(13) & " Please return to Orders or Store to re-order as soon as possible.", vbInformation, "Need to Re-Order Stock" End If End If Next mySelection 'END
iCount = 0
'Go throught each selected 'record' (ItemsSelected) in listbox For Each mySelection In myCtl.ItemsSelected 'Current count of selected items iCount = iCount + 1 'Print value to Immediate Window Debug.Print myCtl.ItemData(mySelection) 'Add answers With myRst .AddNew .Fields("JobDetailsID") = Forms![frmJobs]![JobDetailsID] .Fields("PartUsedNum") = iCount .Fields("PartNo") = myCtl.ItemData(mySelection) .Update End With Next mySelection
Private Sub cmdUnselect_Click() 'UNSELECT BUTTON On Error GoTo ErrMsg:
'Code adapted from ghudson's example on 'http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=52736
Dim myFrm As Form, myCtl As Control Dim mySelection As Variant Dim iSelected, iCount As Long
Set myFrm = Me Set myCtl = Me.lstAnswers
'Count number of selected records/items For Each mySelection In myCtl.ItemsSelected iCount = iCount + 1 Next mySelection
If iCount = 0 Then MsgBox "There are no selections to Un-Select..", _ vbInformation, "Nothing selected!" End If
'Go throught each selected 'record' (ItemsSelected) in listbox For Each mySelection In myCtl.ItemsSelected Debug.Print myCtl.ItemData(mySelection) myCtl.Selected(mySelection) = False Next mySelection
I have a Access table that stores BatchNo,Scandate,NewBatchNo . As I can't attach Access database here so I have exported data from Access to Excel in Sheet1 to show how the data is stored in Access table.
Now I have to write code in VBA that will check the last NewBatchNo in the table . In the attached workbook its 194389. Now vba code should check the NewBatchNo which are blank before 194389 . Now in the records where NewBatchNo is blank , it should add the corresponding BatchNo,ScanDate in the listbox1 in form1.
e.g Sheet2 in the attached workbook stores Bathcno and Scandate of those records where NewBatchNo is null and before the Last used NewBatchNo which is 194389 in our example.
Access 2007-10 Listbox created: List62 (I know I need to rename it, but for now) Multi-select: Extended Row Source Type: Field List Row Source: qryFieldList Open Query: qrySelectedFields (I added primary key to first column, just to have at least one destination field).
Goal: to select multiple fields within listbox, click on command button to open query "qrySelectedFields" with selected fields from list box.This is the code I have on the command_click:
Dim varItem As Variant Dim strSQL As String If Me.List62.ItemsSelected.Count = 0 Then MsgBox "Please select one or more fields.", vbExclamation, "Healthcare REIT" Me.List62.SetFocus End If
[code]....
It does absolutely nothing - doesn't add the fields to "qrySelectedFields", doesn't open the query, notta.
I've been using the following code successfully in Access 2003 & now I need to migrate to Access 2010. The purpose of the code is to use the items that the user selects in the list box to build the criteria of a query. Access 2010 keeps giving me a syntax error when I try to run the query & I don't know why:
My code is:
On Error GoTo Err_Command151_Click
' Declare variables Dim db As DAO.Database Dim qdf As DAO.QueryDef Dim varItem As Variant Dim strCriteria As String Dim strSQL As String
[Code] .....
The syntax error I get in Access 2010 is:
Syntax Error in query expression 'SELECT * FROM qryContractListSummarybyDateContract3TYPEBREAK WHERE qryContractListSummarybyDateContract3TYPEBREAK.Rep ortableName IN('Adbri Masonry NSW');'
Hi, I'm new here, so I hope I'm posting this in the correct place. I've searched the forum to see if there are any existing threads that might help me, but I've not found anything that does... (I think this thread ( http://www.access-programmers.co.uk/forums/showthread.php?t=93444&highlight=Copying+data )may be trying to achieve something similar to me, but I'm a beginner and don't really understand it)
I shall stop waffling! I'm not entirely sure that what I'm trying to achieve is possible, I expect it probably is!
Right, I have a form (frmGroupRegister, which contains exactly the same fields as the table it comes from, tblGroupRegister), which consists of three things:
-GroupDate - The date a group took place on. It is my primary key, as no more than one group occurs on a specific date.
-ParentList (A listbox which contains a query showing the ID number, forename and surname of everyone in a table, tblParentDetails)
-ParentsAttending (A blank listbox)
I would like to place buttons in between the ParentList and ParentsAttending, which would allow users to conduct a 'register' of attendance by copying individual/multiple details from ParentList into ParentsAttending (much like you get when choosing which fields to include in a form when using a wizard for example). I would also like them to be able to remove people from ParentsAttending by using a button in case of accidentally adding the wrong person into the ParentsAttending box.
I'm aware that another, probably simpler way of achieving this would be to use a tick-box system, but I feel that visually, the first method would both look better and demonstrate who is present more clearly.
Any help would be much appreciated, but my Access skills are quite basic and things will probably need to be spelled out for me. I'm using Access 2000 and Windows XP. Thanks for your help, Alice :)
I am using the selections made of the form to generate a query for the user.
I have a CITIES listbox that is populated with values from a stored query.
I would like to make it multi-select and populate a LOCATIONS list box and a NAMES list box based upon the CITIES that are selected.
I have the locations currently populated from a stored query that reads the City selection from the Form. It looks like this
Code:
SELECT DISTINCT (t_location.LOCATION) AS Expr1 FROM t_location INNER JOIN t_asset_master ON t_location.LOCATION_PHY_ID = t_asset_master.LOCATION WHERE (((t_location.CITY)=[Forms]![MasterQueryGenerator]![CityList]));
I also want multi-select so that is you can un-select all and get the results for all cities.
Here is my half thought approach.
Code:
Private Sub CityList_AfterUpdate() 'Dim LocQryStr As String 'Dim r As Integer 'Dim ctl9 As Control 'LocQryStr = "SELECT DISTINCT (t_location.LOCATION) " & _
[Code] ...
I intended to have the variable LocQryStr as the row source but I abandoned the idea of having multi-select when I saw that .Selected(I) never returned true. Its like the values aren't read in this subroutine.
I have a list box called "product list box" based on a query called "searchqry", i also have another listbox called "type list box" , how do i get the type list box to only show "types" based on the section in products list box?
1. On my main form, I have a listbox, I would like to edit the values of the listbox.
To do this, I have a popup form with 2 listboxes, one to have the values of the listbox on the main form, and the other listbox with option values for the 1st
1) how to i pass the rowsource sql of the listbox on the main form to the listbox on the popup form
2) how on closing the popup form, do i update the rowsource sql listbox on the main form from the changed value of the popup form listbox rowsource sql
Okay then, after much trouble and confusion, I finally realized I need to use an Extended listbox in order to allow for multiple items to be selected from a list on my form (rather than the evil multiple selection combobox!).
However, now I am trying to figure out how to make one listbox (IndustryClassification) only be visible if the item "Industry" is selected in another listbox (TypeOfBusiness). Coding I can use for this in the AfterUpdate event of the listbox?
I've got this multiple select listbox which writes data into a textbox:
Private Sub List2_AfterUpdate()
Dim Cursisten As String Dim ctl As Control Dim Itm As Variant
Set ctl = Me.List2
For Each Itm In ctl.ItemsSelected If Len(Cursisten) = 0 Then Cursisten = ctl.ItemData(Itm) Else Cursisten = Cursisten & "," & ctl.ItemData(Itm) End If Next Itm Me.txtCursisten = Cursisten
End Sub
And I've got a SELECT ALL button to select all records in the listbox:
Private Sub cmdSelectAll_Click() On Error GoTo Err_cmdSelectAll_Click
Dim i As Integer
If cmdSelectAll.Caption = "Alles Selecteren" Then For i = 0 To Me.List2.ListCount Me.List2.Selected(i) = True Next i cmdSelectAll.Caption = "Alles De-Selecteren" Else For i = 0 To Me.List2.ListCount Me.List2.Selected(i) = False Next i cmdSelectAll.Caption = "Alles Selecteren"
The only thing is that when I use the SELECT ALL button, the function List2_Afterupdate doesn't work anymore. There must be a simple solution but I just can't figure it out. Can anyone please help me?
Hopefully somebody can help me on this one. I searched the whole internet and access forums, but I didn't find the exact solution for my problem.
I've got a table with students, a table attendance, where I now only save the students who are absent, but I would like to save also the students who are PRESENT (at the same time). I've got a combobox where I filter the Class, which then updates a listbox with the students from that class. What I do now is select the students from the listbox and then press a save button and it saves the records to the table absence with STATUS: ABSENT.
I would like to save the NON selected students also in that table, but with PRESENT in the column STATUS.
I thought of making another listbox next to it, where after selecting the absent students, they wil apear and disappear in the PRESENT table so I can store all the information. But the only problem is that I can find this solution when the listbox is populated by a list of values instead by a table or query. And the other solution is to store the temporary data into 2 different tables, but that's not working for me because it's a multi user database and everything will be messed up.
Hope that someone can help me, I will be very happy.
Firstly, is it possible to hide unchecked values in a listbox? I have a user with several roles and I want to only show the ticked roles in the listbox.
Secondly, can you create a hyperlink on listbox values? i.e, if I click on "Manager" in the roles listbox, it follows that to another form and opens the record about managers?
Works great, but when I hit the number "3", (3 times in row) it will let me into the form. I want it to not let me in IF I don't know the password.
Where did I go wrong?
Private Sub Form_Load() Dim pw As Variant
If InputBox("What is the password?", "Password") = "1" Then Else MsgBox "Invalid Password", vbCritical, "Sorry Charlie" DoCmd.Close If InputBox("What is the password?", "Password") = "2" Then Else MsgBox "Invalid Password", vbCritical, "Sorry Charlie" DoCmd.Close End If End If
I protect my code from people being able to read it by setting a password on the code from Tools > Properties, selecting the Protection tab and entering a password, and clicking "Lock Project"
Is there a way to write code that will remove that Lock Project check and check it back on?
I've looked through the Application.SetOption command and it doesn't seem to be one of the choices. It would be very helpful if someone knew how to do this.
all of a sudden now, when i open my form, its not displaying any of the previous data that i stored in it!! All the data is still in the table, and when i add data it goes into the table!! I checked properties and the record source and everything is ok there, what have i done wrong guys...HELP!!!!
I purchased a copy of Office 2003, on Ebay, for less than half the price it normally sells for. I created databases, which work well on my computer. However, when I copy them over to the office computer from my computer, via Flash memory stick, the program does not run. The message seems to indicate a problem with registration. When I installed Access, it asked me for a registration key, which I did provide. After that it worked-not activation process. Does this mean that you can only use the computer you created the database on to run it, or that I do not have a proper version of Access 2003? I cannot transfer, from my home computer, to the office computer. Is this Microsoft paranoia again? Subsequent uninstalls and reinstalls of the program did not ask for the installation key. What should happen? I would like to resolve this major problem and your help will be greatly appreciated. The program is flaky. Also, Switchboard does not work-must use Option Box.
These questions most user must know about initial installation and copying mdb files to other computers -please reply.
i have a string variable denoted by cui and i need it to take value from table tblPersoaneJuridice from field CodUnicInregistrare. CodUnicInregistrare and NumarInregistrareRegComertului is text.