Quantcast
Channel: Access for Developers forum
Viewing all 14673 articles
Browse latest View live

Update all records on screen when I hit calculate

$
0
0

Anyone,

  I have many records that I got from the db and display the record set on the screen for all the records.  Then I have a button where I calculate some values on the first record on the screen on the screen.  What I want to do is update all records on the screen with the new values that will need to be calculated for each of them.

i.e.  I change the amount of a percentage.  Then I want to update all records with on the screen using that new percentage.  The control source for the fields is the database column name.  How can I loop through the screen records and recalculate all of them with this updated percentage field?

I am thinking I need to update each record on the table and then do a me.form.refresh to display the updated values on the screen.  Yet, when I tried that I keep getting the dialog box stating that the record has changed before I try to save the new values to the table.  How could I get this to work?  I look forward to hearing back.

Jerry


Negative Percent field when entered by cursor is not displaying as it should be.

$
0
0

Everyone,

  I have a form where the fields control source is the database column.  This field is calculated on the screen and it displays as a -2.28, which is correct.  When I tab to the field, everything is fine.  Yet, when I put the cursor on the field, directly it changes to a value as -0.022755158951478.  I have it defined as percent with 2 decimal places.  How can I fix this to display as -0.0228 when I put the cursor on the field?  Thanx in advance and I look forward to hearing back.

Jerry

help with mid function and #func!

$
0
0

i have a field that return a strung as "1 year 10 months 12 ,days"

i need to pull the days 

i used the function  ,pos: InStrRev([diff],",")

and   days: Mid([diff],[,pos]-3,2)   (-3 because my language is Right to left)

now if the result in ",pos" field is 0 than i get #func! error (I need him to give me zero value for a calculating field)

I have tried many combinations with "iff" And other functions

BTW i  can remove the "comma" from "days" 

product toevoegen

$
0
0

Ik wil een query maken die een product toevoegt aan een tabel

voorbeeld: ik heb de velden product en aantal. De query als bij aanklikken worden uitgevoerd en één exemplaar in het veld aantal toevoegen. 

Run On Timer event for specific days and times

$
0
0

Greetings,

I have an Access 2016 database (32 bit) on a Windows 10 machine. I have a form named frmMain with the Timer Interval set for 1 minute (60000). Each minute I need the On Timer event to run a vba sub called ImportShipped. I want this process to run on specific days and on specific times. The application I’m extracting this data from will only allow me access on specific days of the week and during a specific time range.

I created two tables. The first is named tblImportDays with a short text field called ImpDay that contains the long name of the day of the week (ex: Monday, Tuesday) the vba is to run. The second table named tblImportTimes contain a Date/Time field with the specific times (ex: 3:00:00 PM) the vba is to run.

I need help creating a vba that compares the current day of the week and current time to these two tables to determine when to run the On Timer event.

I appreciate any suggestions.

Regards, Kevin

Replace sub for MSCAL with date picker in accdb 216

$
0
0

Hi,

I switched to new PC with Win 10 and MS Office 365 (2016) from Win 17 and MS Office 2003. II convert a mdb database to accdb. In accdb I removed a reference missed reference to MSCAL, and nor there are no complaints to missing MSCAL.

In accdb I  have several forms with textboxes in date format. The boxes have how date picker and date properties set, so on pen form the current date is are displayed in boxes data pickers activated on clicks, date changed and displayed in boxes. So far so good.

But I had a several MSCAl subroutines for each of boxes like that

Private Sub Calendar0_Click()
    If Calendar0.Value > Date Then
       Calendar0.Value = tbDate.Value
       MsgBox "Days beyond today are not allowed!" & vbCrLf & "Select today's or one of past days!"
    Else
        tbDate.Value = Calendar0.Value
        tbDate.SetFocus
        Calendar0.Visible = False
    End If

This is for not selecting the future days. Calendar0 is for MSCAL Control.

I need to write a similar procedures for Access Datepicker. But I do not know how to declare a DtePicker variable, what event function to use, and an API to use. I tried but with no success. Te original mdb files was written 9 years ago

Any help will  appreciated

Data Type Mismatch

$
0
0

I am trying to get this VBA code to work, which allows you to email from Access.
I am getting a 'Data type mismatch in criteria expression'.

I can't see anything that looks wrong to me, but I am not very experienced.
Here is the Code:

Private Sub btn_Send_Click()
    On Error GoTo Err_btn_Send_Click

    Dim stWhere As String       '-- Criteria for DLookup
    Dim varTo As Variant        '-- Address for SendObject
    Dim Message As String        '-- E-mail text
    Dim DateSent As Variant      '-- Sent date for e-mail text
    Dim Subject As String     '-- Subject line of e-mail
    Dim EID As String    '-- The ticket ID from form
    Dim stWho As String         '-- Reference to Email_ADDR
    Dim From As String    '-- Person who sent the email
    Dim strSQL As String        '-- Create SQL update statement
    Dim errLoop As Error

    '-- Combo of names to assign ticket to
    stWho = Me.cboTo_Key
    stWhere = "Email_ADDR.ID = " & "'" & stWho & "'"
    '-- Looks up email address from Email_ADDR
    varTo = DLookup("[Email]", "Email_ADDR", stWhere)

    stSubject = "Subject"

    'EID = Format(Me.EID, "00000")

    stText = Me.Message

    'Write the e-mail content for sending to assignee
    DoCmd.SendObject , , acFormatTXT, varTo, , , stSubject, stText, -1

    'Set the update statement to disable command button
    'once e-mail is sent
    strSQL = "UPDATE Email " & _"SET Email.Sent = -1 " & _"Where Email.EID = " & Me.EID & ";"


    On Error GoTo Err_Execute
    CurrentDb.Execute strSQL, dbFailOnError
    On Error GoTo 0

    'Requery checkbox to show checked
    'after update statement has ran
    'and disable send mail command button
    Me.Sent.Requery
    Me.Sent.SetFocus
    Me.btn_Send.Enabled = False

    Exit Sub

Err_Execute:

    ' Notify user of any errors that result from
    ' executing the query.
    If DBEngine.Errors.Count > 0 Then
        For Each errLoop In DBEngine.Errors
            MsgBox "Error number: " & errLoop.Number & vbCr & _
                   errLoop.Description
        Next errLoop
    End If

    Resume Next


Exit_btn_Send_Click:
    Exit Sub

Err_btn_Send_Click:
    MsgBox Err.Description
    Resume Exit_btn_Send_Click

End Sub

This is the Email table structure:
EID: Autonumber
Subject: Short Text
Message: Short Text
Date Sent: Date/Time
To Key: Number
Sent: Yes/No

The SQL query looks OK to me, but perhaps I am missing something!


TEH

SQL Server Express 2017 Connection Failed

$
0
0

This is my first attempt at running Access with a SQL table back end

I just converted Access tables to SQL and am trying to run an Access 2016 front end that links to the SQL tables

The SQL tables are on a Server (Win 2012 R2) drive, the front end in on a Windows 10 PC

When I run the front end there is a long delay then an error message:

Connection Failed, SQL State '08001', SQL Server error 0 [SQL Server native client 11] unable to complete process due to delay in opening server connection

followed by a SQL Server login popup with the Server SPN blank

If I click ok the application runs but the same error occurs each time I run the application

This application runs without delay when the tables are local vice on a network drive


Code working from One form but not the other

$
0
0

The report opens correctly from frmHorseInfo but not from frmInvoice, could it be that frmHorseInfo has a bound text box tbhorseID, where as frmInvoice has a unbound Combo box [cmbHorseID] that is its HorseID

Thanks for any help.............Bob

this is the error I am getting........

Private Sub Report_Open(Cancel As Integer)

If CurrentProject.AllForms("frmHorseInfo").IsLoaded Then
    Report.RecordSource = "SELECT Distinct tblInvoice.InvoiceDate,tblInvoice.InvoiceID AS InvoiceID," _
    & " tblHorseInfo.HorseID, funGetHorse(0,tblHorseInfo.HorseID,false) AS HorseNamed, [StableReturnDate] " _
    & " FROM tblInvoice,tblHorseInfo where tblHorseInfo.HorseID " _
    & " = tblInvoice.HorseID" _
    & " and tblInvoice.HorseID=" & Forms!frmHorseInfo![tbHorseID]
    Report_rptHorseExpenses.tbInvoiceDate.Visible = False
ElseIf CurrentProject.AllForms("frmInvoice").IsLoaded Then
    Report.RecordSource = "SELECT Distinct tblInvoice.InvoiceDate,tblInvoice.InvoiceID AS InvoiceID," _
    & " tblHorseInfo.HorseID, funGetHorse(0,tblHorseInfo.HorseID,false) AS HorseNamed, [StableReturnDate] " _
    & " FROM tblInvoice,tblHorseInfo where tblHorseInfo.HorseID " _
    & " = tblInvoice.HorseID" _
    & " and tblInvoice.HorseID=" & Forms!frmInvoice![cmbHorseID]
    Report_rptHorseExpenses.tbInvoiceDate.Visible = False



Debug.Print Report.RecordSource
End If
    Debug.Print "Recordsource = " & Report.RecordSource
End Sub

            

xxx

Rename a list of files with vba without moving it

$
0
0
Hello everybody

i have a directory c:\

123 - AAAAA
45678 - BBBBB

How can i rename the files in 

AAAAA - 123
BBBBB - 45678

without touching the subdirectories
Thanks for all and happy new year

Access - search across multiple base tables (SELECT with JOINs) & show results in parent form and subforms

$
0
0

Background - there exists the following for a residential property database:

Tables in SQL Server 2017

  • H_ADDRESS
  • H_IMPROVEMENT

Access 2016

  • Linked tables to those in SQL Server
  • Parent Form - frmSales
  • Sub Form - frmImprovement

So the parent form, frmSales, contains subforms e.g. frmImprovement. I'm not wanting to deviate from parent and subforms.

Requirement

Provide the user two search methods - simple and advanced.

Simple

A new form will be created that has fields for basic search parameters like city (address), year built (improvement), etc. This form will need to run a query that does SELECT with JOINs and WHERE conditions for the values of the search parameters. I know how to write the query. How do I get a button to run the query and open the parent and sub forms with the result set?

Advanced

I'd like this to work like Filter by Form -- the user views the parent and sub forms, initiates a search, enters search values, runs search (the SELECT with JOINs), and views the result set. Is it possible to have the parent and sub forms support something equivalent to Filter by Form? (doesn't have to actually be Sort & Filter > Filter by Form out of the box... vba custom code is agreeable)


Attaching image to table (Local Images) to an Attachment field access 2016

$
0
0

I am trying to add image to an image field in a table in Access 2016 using VBA

Here is the scenario:

Table contains field for attachments named [Photo]

Table = [Term]

The photos (over 3,000) all have the ID number in the file names but are numbered (Several Photos for one record)

So the file names that go with the Record ID  examples: 1-160304-0-t1.png; 1-160304-0-t2.png; 1-160304-0-t3.png; 1-160304-0-t4.png; 1-160304-0-t5.png

With the LEFT 1-160304 being the record ID

Here is something that might be helpful, there is a field in the database [ImageName] that refers to image file name, but it contains the wrong format: 1-160304-0-t1.jpg for 1-160304-0-t1.png, this is easily fixed so that file name "MIGHT" refer to the image I need to attach via VBA. So I could use this Field [ImageName] to match the file I need to upload.

So I am looking for example code to do this,

Taking the file name from a field matching the appropriate image file and then attaching it to the attachment [Photo] field in the Access 2016 table

I can insert one image using the VBA LoadFromFile but I am having a hard time getting this to do all records.



Microsoft Visio Standard 2013 show empty layout

$
0
0

Hello All,

Need your help on this issue.

MS Visio only show empty for most of its layout.

Do you guys know whats happen and solution for this?

Thanks.

Broken window

$
0
0

When I have a form in MS Access 2016 in design mode, the scrolling is not synchronized. It looks like a broken window. Only the right bottom part of the form performs a scroll. The rest stays frozen.

This only happens when I use the windows "extend desktop" option when I use a second monitor on my laptop. It has nothing to do with video drivers because I experience this error like many other developers on several brands of laptops with different video drivers.

Pleas help


Jim de la Combe freelance VBA developer

ODBC Timeout property doesn't impact how long it takes for a query to timeout

$
0
0

Per docs and postings the ODBC Timeout property is supposed to define the number of seconds before an query's odbc connection attempt is ended. But I've experimented and find that it has no impact whatsoever. If I set the property to 2 seconds it still takes anything from 21 to 40 seconds for the sql server Connection failed dialog appears.

All I can think of is that my testing methodology is wrong. I am interested in controlling how to control the number of seconds before the query gives up when a sql server database is not available on the network. To test, I take the sql server offline. I'm wondering if the odbc timeout property is only meant to deal with the timeout value for queries that can actually be invoked?

If that's the case, is there a way to test to see if a sql server is available before attempting to run a query?


How To Import Into A Table with Multi-Value Fields

$
0
0

Hello:

I have a table with a multi-value field that contains states in which a company does business.  It is multi-value because there can be more than one state.  I tried to import a text tab-delimited file in which the data was arranged as follows:

Field1 Tab Field 2 Tab OR, WA, CA Tab

The "State field contained the multiple entries separated by a comma (like they appear in a query of the multi-value field), but it won't accept it.  Does anyone know how to import into a multi-value field?

Thanks,

Rich Locus, Logicwurks, LLC

 

Want to create Table Name STATS with Fields ID(Integer), Month(Integer), Temperature_F(Integer), Rain_Inches(Integer) with certain Conditions such as Month values should be between 1 and 12, Temperature_F should be between-80 and150,Rain_inchesbetwen0&10

$
0
0

The Query I wrote is 

Create Table STATS
(ID Integer, Month Integer  CHECK (1<=Month<=12), Temp_F Integer CHECK (-80<=Temp_F<=150), Rain_I Integer CHECK (0<=Temp_F<=10), Constraint STATSID_PK Primary Key (ID));

However, while I run this it is showing error


put control in top right corner of Tabbed form (or when full screen)

$
0
0

Thank you for taking the time to read my question.

I want to put a "close" button at the top right corner of my form so that it shows up ... in the top right corner. The catch is (so far) that the forms are in Tabbed view so the size of the form depends on the users screen. 

How do I get my close button to position to the top right of the screen regardless of screen resolution?

thanks

Allow a Form to Add Multiple Records at a Time

$
0
0

Hello,

I'm creating a database from scratch, was nearing completion, and have run into 2 issues that the users have requested.  The scenario is that I have a database with 5 tables that need to be edited for each new sample result from lab equipment, the tables being

  1. The status of the lab (such as barometric pressure.)
  2. Status of the instrument (which instrument was being used) which references the 1st table.
  3. The type of sample being analyzed.
  4. A many-to-many table joining tables 2 and 3 so that each instrument and sample are recorded as well as data pertaining to that current sample test (such as time test was performed), with this form referencing tables 2 and 3.
  5. A sample will be run on a single instrument usually 2 times to make sure that a single test didn't happen to give a wrong value due to make sure the test results are repeatable, but sometimes it is done 1 to 4 times due to different circumstances, so there is a result table which references table 4.  This is done so that I don't have table 4 with 4 columns to enter data in, with most of the time the last 2 columns having no data in them which I was taught violates normal form for databases.

Given this, here are my problems.  First, I have setup a form to allow lab personnel to enter data into Microsoft Access through one form instead of 5 different forms, on for each table.  This is done by having a form for the 5th table have a subform for table 4, which has subforms for tables 2 and 3, and then table 2 having a subform for table 1, with combo boxes allowing a user to choose data from previous records for all the subforms.  So I have a form that is 4 levels deep due to subforms.  The problem is that to enter NEW data, a user currently has to:

  1. Open the form for table 5 that has the subreports,
  2. right-click on the combo box that changes the data for the subform that is for table 4,
  3. select "Edit List", then has to edit list again for the other combo boxes for the forms for tables 2 and 3,
  4. for the form for table 2 need to repeat steps to reach the form for table 1,
  5. select New Record,
  6. enter the new data,
  7. click save,
  8. then back in the subform for table 4 has to click refresh all, (Note: If an instrument has already been used to analyze a sample once during a day then the user will only have to select the value from the combo box for instrument status for that day so steps 3 - 7 can be skipped which does save some time for entering new data.)
  9. then click new record,
  10. enter the new data,
  11. save,
  12. go back up to the main form,
  13. refresh again,
  14. select from the combo box the primary key value for the new value entered for the form for table 4,
  15. FINALLY enter the first result from the test,
  16. and then for tests done on the same sample, just like how Steps 3-7 can be skipped, steps 2-14 can be skipped when if more than one test is being done on the same sample by copying the record into a New Record for the form for table 5.

I've talked with the users and we agree that this is ridiculous to have to be done every time a new sample arrives in the lab that needs to be analyzed.  So the first question is, is there anyway to setup a form so that a user can just select everything without going through multiple forms, refreshing, etc. and have as few steps as possible, preferable (not needing to be this short, but anything shorter is better) something like this:

  1. Open the form for table 5,
  2. create a new record,
  3. allow values to be entered for the lab condition for table 1, instrument status for table 2, type of sample for table 3, conditions of instrument when analyzed for table 4, and then the actual results for table 5,
  4. and then copy that record for each time the sample needs to be re-tested and change the result so each result is recorded.

Again, if more steps than that are needed, that's fine, but having to do 16 steps for each new sample at the beginning of each day (10 steps if the instrument has been run the same day) is ridiculous, so anything shorter than that would be great.

The second things that the users have requested, and this is 2nd in priority to the 1st problem mentioned above) is to instead of having to copy the final form each time the sample is rerun on an instrument is to have another box to enter data appear in each time a result box is filled in.  For example, when you go to an self-checkout at a store you don't need to get a new transaction for each item.  You scan an item, keep scanning items until you have nothing left in your cart, and then select checkout.  Likewise, the users want once one result has been entered for another box to appear (which I know how to do with events for labels and text boxes so they will only show if there is data in another box) and then to be able to enter values into the boxes until all test result have been entered.  This way all the results for a sample being tested can be entered and reviewed on the form at the same time so there will be no chance of entering the same result twice or forgetting to input one.

Again, the users really need the steps being cut down from 16 steps for new samples, that is the top priority, while being able to enter multiple sample results at a time so New Record doesn't need to be selected for each retest is the bottom priority.

-Tommy

Textbox on Access VBA form passing null value though it contains a value in it?

$
0
0

I have created a search form as shown in the image. There is a text box for the user to provide the search text. Once the use enter search text he can tiger the search event by two means, either the user can click on the search button or he can simply press the enter key. The problem which I am facing is very strange on the button click event its working fine. But on the press of enter key for the first time the text box is passing the value which was entered in the text box from the previous event and if I press the enter key for the second time then the current value is passed.

For instance on the form load the text box is empty then I enter the search text as "Ali" and press enter key then the value "NULL" is passed and once again I press enter key then the value "Ali" is passed. I am unable to understand why.

I will be so thankful if any one can help me on this.

The code is give below

Option Compare Database

Option Explicit

Private Sub btnSearch_Click()
    Dim SQL, strSearch As String
    strSearch = Nz(Me.txtSearch.Value, "")
    SQL = "SELECT tbl_mst_Employee_Details.emp_ID, " _& "tbl_mst_Employee_Details.emp_Name " _& "FROM tbl_mst_Employee_Details " _& "where [emp_Name] like '*" & strSearch & "*' " _& "ORDER BY tbl_mst_Employee_Details.emp_Name;"
    Me.lstEmployee.RowSource = SQL
    Me.lstEmployee.Requery
    Me.txtEmpID.Value = ""
    Me.txtEmpName.Value = ""
    Me.Refresh
End Sub

Private Sub Form_Load()
    Me.txtEmpID.Value = ""
    Me.txtEmpName.Value = ""
    Me.txtSearch.Value = ""
End Sub

Private Sub lstEmployee_Click()
    With lstEmployee
        Me.txtEmpID.Value = .Column(0)
        Me.txtEmpName.Value = .Column(1)
    End With
End Sub

Private Sub lstEmployee_DblClick(Cancel As Integer)
    Forms!frmEmployeeShiftDetails.txtEmpID.Value = Me.txtEmpID
    Forms!frmEmployeeShiftDetails.txtEmpName.Value = Me.txtEmpName
    DoCmd.Close
    Forms!frmEmployeeShiftDetails.txtEmpID.SetFocus
End Sub

Private Sub lstEmployee_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        lstEmployee_DblClick (0)
    End If
End Sub

Private Sub txtSearch_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        btnSearch_Click
    End If
End Sub


Viewing all 14673 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>