Modules & VBA :: Viewing Values That Exist In Table TblTest2 To User?
Aug 5, 2013
I'm having trouble viewing values that exist in table 'tblTest2' to the user. The first set of code (below) doesn NOT work. Yet the second set of code (all the way at the bottom) DOES work. And by work I mean that it erases the old values and only puts the tblTest2's new values. The first set of code has values but they are not the right ones. The second set of code has the correct values for its statement...
Code:
strTable = "tblTest2" 'Table for storing values for viewing purposes
DoCmd.DeleteObject acTable, strTable 'Delete tblTest2 old values
CurrentDb.Execute "CREATE TABLE tblTest2 " _
I'm trying to write some Code with the target to take a value from a textbox (out of a form) and a pregiven value (in this case = 2) and enter them in a new record in a table. But only if there is not already a record with the exact same combination of these to values. When done, the same button should proceed you to the next form (but this code is not already implemented in the fragment below) even if no values are added because they already exist in this combination.
Code: Public Function GetID_PatientStudiesGroup&() GetID_PatientStudiesGroup = [Forms]![frm_PatientStudiesGroupTZP]![ID_PatientStudiesGroup] End Function Private Sub BPRS_T1_Button_Click() Call GetID_PatientStudiesGroup& Dim strSQL As String
[Code] ....
As you can see, I tried to use a function to refer to the value out of the form, because I didn't find out how to refer to a form in an SQL Code.
Just to give you a better overview: The table where the information should be added is named "tbl_PatientStudiesGroupTZP". The form where you find the Textbox "ID_PatientStudiesGroup" (with the value I need to transport) is named "frm_PatientStudiesGroupTZP". Every part (except the WHERE NOT EXISTS part) worked perfectly for itself, but not when thrown together.
I want to develop my database and forms to fit a 1600 x 900 resolution screen and would like to know, whilst I am in the Developer mode of Access 2007, is there a key that I can press that will switch to display the database/forms so that I can see what the User will see?
I've got a form (frmEdit) that allows users to search tblMain for records using a bunch of unbound controls and a dynamically created SQL statement. Search results are displayed in a subform (subMain), and the current record in the subform is displayed in a set of bound controls on frmEdit.
Now the important bit: There is a set of unbound checkboxes on my form that allow the user to change which fields are visible in subMain. This is accomplished by the following:
Code: Private Sub chkName_AfterUpdate() If Me.chkName = 0 Then Me.subMain.Form.CorrespondingField.ColumnHidden = True Else Me.subMain.Form.CorrespondingField.ColumnHidden = False End If End Sub
Certain fields are visible by default, but the user may want to change which fields those are. Here's what I've done so far to accomplish this:
Created a button (btnChangeDefaults) that opens a form (frmChangeDefaults)
Put checkboxes for each table field on frmChangeDefaults
Put a "Cancel" button (btnCancel)* and "Done" button (btnDone)** on frmChangeDefaults.
*btnCancel just closes frmChangeDefaults without making any changes to frmChangeDefaults or frmEdit
**btnDone changes Forms.frmEdit.Form.chkName.DefaultValue to Me.CorrespondingCheckBox.Value and then closes frmChangeDefaults
This all seems to work quite well, actually. Debugging confirms that the default values of the checkboxes on frmEdit are indeed changed when I click btnDone. But when I close frmEdit and re-open it, the default values return to what they were prior. This happens even when:
I close frmEdit using DoCmd.Close acForm, "frmEdit", acSaveYes
I close frmEdit after using DoCmd.Save acForm, "FrmEdit"
I save frmEdit manually by right-clicking and pressing save
The following SQL statements run with no errors, but I can't see the output of the SQL statements. What is wrong with my "Debug.Print" or "rs" statement ? I would like to see the results. The SQL statements works when I save them to a query.
Dim db As DAO.Database Dim rs As DAO.Recordset Rem Dim intResult As Integer Dim strSQL As String Set db = CurrentDb
I'm having problems creating a second subfolder in the main folder.
The main folder is used to keep inside the reviews of clients inside.
The code I have now, will only create a main folder if it does not exist and then a subfolder with the BIN nr, type review and date. If the client would have a diferent ones and in diferent years. So if it has first "Prototype Model", the next one could be "Prototype Review". The part of the code that checks if the main folder exist works, but how to let the code create in the main folder the second review subfolder? Please see below code I managed so far:
Code: Private Sub btn_Create_Folder_Click() 'XXXXXXXXXX working onXXXXXXXXXXXXXX Dim path1 As String Dim path2 As String path1 = "C:Test_FolderMedium" & Me.BIN & "_" & RTrim(Me.LE_Name) & "" path2 = "C:Test_FolderHigh" & Me.BIN & "_" & RTrim(Me.LE_Name) & ""
I found and modified this code to allow me to check (fast) if a file exist on a http server or not (without downloading it).
Code: Public Function CheckNetFile(WebFile As String) Dim XmlHttpReq As Object Set XmlHttpReq = CreateObject("Microsoft.XMLHTTP") XmlHttpReq.Open "HEAD", WebFile, False
[Code] ....
In the above code I managed to declare Webfile as a string so I can call on it later but one thing I still need to tweak is to also get a result out of the test code in a better way than having to publically declare the "CheckNet" variable somewhere else in my app.
First prize would something like this:
If CheckNetFile ("http://www.mysite.co.za/test/test.txt") = 1 then "Yes" else "No"
How do I build the 'booleon check' into the original function?
I want to do it bring up a form from which the user can send an email, and on the form is an unbound text box [Text1] in which the user can paste the attachment path.
Code: Dim olApp As New Outlook.Application Dim mItem As Outlook.MailItem ' An Outlook Mail item Set olApp = CreateObject("Outlook.Application") Set mItem = olApp.CreateItem(olMailItem) ' Add the To/Subject/Body to the message and display the message
[Code] ....
So, when I paste the file location into Text box [Text1] I get the Run Time error that the path does not exist or is not valid. Yet when I use the next line which is the same path, all is OK.
I am trying to import data from excel into one of Access table but it showing error F30 does not exist in destination table. I have checked headings which are matched. Same sheet tried to import in access successfully, but unable to import specific table...
I currently have this set as the forms default recordsource (which works just fine):
Code: SELECT TOP 5 tblUsers_Phone_Book.EMAIL_ADDRESS, weightedDL('me@mine.com',[EMAIL_ADDRESS]) AS Expr1
And I have this vba to dynamically switch around that email address.
Code: Private Sub Form_Load() Dim intPos As Integer Dim strControlName As String Dim strValue As String Dim sSQL As String If Len(Me.OpenArgs) > 0 Then ' Position of the pipe
[Code] ....
If I msgbox the sSQL - it shows identical to the default recordsource but I get the error:
The error message I get is:
Run-Time error '2580' The record source 'SELECT TOP 5 tblUsers_Phone_Book.EMAIL_ADDRESS, weightedDL('me@mine.com',[EMAIL_ADDRESS]) AS Expr1' specified on this form or report does not exist.
I tried copying the exact working default sql into the vba and get the same result.
I want to check if data entered in a form field is existed
The form is bounded to a table
I used this code
If DLookup("Telegram_Number", "tbl_Violation_Of_Building", "Telegram_Number Like " & Forms!frm_Add_Violation_Building!Telegram_Number) Then MsgBox ("number existed") Me.Telegram_Number = "" Else End If
everything is ok but if the data is existed the database show the message and clear the field but i'm getting a Run-time error
'-2147352567(80020009)': the macro or function set to the beforeupdate or validationRule property for this field is preventing [ISF] from saving the data in the field
I guess the problem because the form is bounded to a table so he will save automatically
My solution is to unbound the fields and save the data via vba but is there any solution with a bounded form???
I have a database that has 2 tables. Table A and Table B. Table A is my primary table. On this table I have 2 fields. The first field is a LOOKUP Field that looks up information from Table B and displays my selection in the field on Table A. Then using DLOOKUP I automatically input the information in the Second Field on Table A based upon the selection from the First Field.
This is working mostly correctly. However, the problem is, when I click on the next record in the table, it automatically changes the Second Field on that record to the same value as the record before it and continues this trend each time I click on another record. This occurs without me making a selection in the first field. If I make a selection in the first field it does change the Second Field to the Correct Value, but then the next Record has the same issue.
How do I go about fixing this so it doesn't change the value with the change of the record. Only change if I change that particular field within that 1 record?is there a way to restrict the Value's in my lookup field to only include the Values from Table B that aren't already in Table A?
I have two tables. The first one contains customer information. Primary key is custno. The second one contains customer logins, primary key is also custno.
What I want to do is to view customer information that does not have customer logins.
I have a table (tblConversions) that I'm using as a base for replacing values in a different table. tblConversions is set up as such and is made up of nearly 100 records:
ID LABEL CODE 1 Ashaway ASH 2 Barrington BAR 3 Bristol BRI 4 Jesse Smith BUR ....
Another table (tblSysItemLoc) has nearly 1,000 records with a field for Location Names such as Ashaway New Books, Ashaway Fiction, Ashaway Non-Fiction, Barrington DVDs, Barrington Reference, etc. Other fields in this table are just statistics.
What I need to do is loop through tblConversions, and find in tblSysItemLoc where the Location field Starts With the value from tblConversion.LABEL and replace the Entire field with the CODE. For example, from tblSysItemLoc "Ashaway New Books" gets changed to "ASH", "Barrington Reference" gets changed to "BAR", etc.
I feel like I need a loop inside of a loop, but I'm not sure where to begin. Loops are not my specialty.
I have a file that I want to import on a daily basis and append to an existing table in my database. The date changes each day. I want to create a query that checks to see if the date (of the first record) already exists before I import and append the new file. If it does, I want to show a message saying something to the effect of "This file has already been imported".
I am new to VBA and I'm trying to write a query that will update a table with dates based on user input. For example a user will run data each Monday and that date will be day01. The date table has 28 days total and I need each day row to update with the next date i.e. day01 is 12/30, day02 is 12/31, day03 is 1/01 etc..I am having issues just running the update the query. I get a too few parameters error message on the strsql statement. There are only two columns in the table, order_day(date column) and date_value(text). I want to update order_day. I also need creating a loop so it knows to go back and add days to the other values.
Here is what I have:
Code: Sub Update_Dates() Dim rs As Recordset Dim db As Database Dim lmsg As String Dim transactiondate As Date Dim strsql As String
I have purposely used "False" to ensure that the first line in my spreadsheet is ignored. This is because the first line in my spreadsheet contains headings that do not match the column names in my table.
I do not wish to change my headings as end users will be making use of my application and they will not like headings such as "int_FactoryID". Likewise I do not want to change the column names in my table to words such as "Factory ID" as this would be a bad naming convention.
Is there a way to use TransferSpreadsheet without necessarily matching the headings in the spreadsheet to the column headings?
Is there a way for TransferSpreadsheet to ignore the headings and assume that the first column in the spreadsheet needs to go to the first column in my SQL Server table?
Validating field from a query. I have a table with a field that has a value number that I need to validate that that number exist in another table in a field
Table1.field1 Number Table2.field1 number
So let's say a have in table2.field1 the list 1 2 3 4 5 8
In table1.field1 I need to validate that the number I enter is present in table2.field1 so 1 would be ok but 6 invalid and it can't be a from list statement because I need the person to enter a number and get no error or get invalid number.
I have a file that I want to import on a daily basis and append to an existing table in my database. The date changes each day. I want to create a query that checks to see if the date (of the first record) already exists before I import and append the new file. If it does, I want to show a message saying something to the effect of "This file has already been imported".
I have made a table and I enter data in that table through a form. The form also include two sybchronized comboboxes. When I select a category in one combo box, corresponding items are selected in second combo box. The problem is that when I select the category in the form (with ID+Category Name), it stores only the ID in the table. How can I see the Category Name in the table (which is the control source of the form) instead of ID?
What I'm stuck on is the filepath. The file path changes everytime. So I would like to have either the open dialog box (I've tried many different versions that I found on the web.) or to search by the account name for the folder and place the text file in there.
Here is one that is closely working how I want it to:
This is a function that I found, that opens a dialog box for the user to select the folder location. It works, but I can't seem to get it to work properly.
It prompts, the location, then once you select it and press ok. It will add the folder name to the full file name, and place the file in the default root path. Not the selected folder path.
So in the end it will look like this:
D:1_MainMyFolderName_MyTextFileName.txt
I'm somehow stuck on getting to seperate the file path from the file name, so you it look like this:
D:1_MainMyFolderNameMyTextFileName.txt
Code:
Dim MSg As String Dim SelectedDir As String Dim SelectedDirFinal As String Dim SelectedDirName As String Dim StrFolder As String
[Code] ....
I think it should be something very easy, that I just need a pair of fresh eyes to look.
I've tried the Fileobject, FileFolder method, but can't get the quite work properly.