MajP
You've got your good things, and you've got mine.
- Local time
- Today, 02:59
- Joined
- May 21, 2018
- Messages
- 9,999
Thx, i'll give it a go.This may do something similar. Uses a temp table to allow mapping of fields between two tables. I defaults the selections if the names are close.
When you delete a form, rest assured that no data is lost. All your information is safely retained in the tables of your database. The tables don't care if you make or remove forms that work with them, so there's no issue with the method. Just double check that the info you put in the form is saved in the table before you delete the form and you'll be fine.Do you think that the method would create a problem with the loggin of info in Access. Cannot find anything that says Access saves the info if the form is deleted. ???
Private Sub Comando0_Click()
'make form
Dim newForm As Form
Set newForm = Application.CreateForm
'define some utilitary variables
Dim i As Long, j As Long, fieldCount As Long
Dim someValues As String
'set an imaginary number of textboxes
'could be your field count
fieldCount = 10
'define placeholder variable for combos
Dim currCombo As ComboBox
'loop field count
For i = 1 To fieldCount
'make combos
Set currCombo = Application.CreateControl(newForm.Name, acComboBox)
'give them some props
currCombo.RowSourceType = "Value List"
currCombo.Top = i * 500
currCombo.Left = 600
currCombo.Width = 5000
currCombo.Height = 300
'add some data for the combo
'guess it'll be dynamic
For j = 1 To 3
someValues = someValues & " something in combo " & i & " (" & j & ")" & ","
Next j
currCombo.RowSource = someValues
'restart strings for next combo
someValues = ""
Next i
Dim closeButton As CommandButton
Set closeButton = Application.CreateControl(newForm.Name, acCommandButton)
closeButton.Caption = "Close form"
closeButton.OnClick = "=CloseWithoutSave(""" & newForm.Name & """)"
'give it some name for show
newForm.Caption = "MyForm"
'add code
newForm.HasModule = True
'open form
DoCmd.OpenForm newForm.Name
'you don't have to save it
End Sub
Public Function CloseWithoutSave(frmName As String)
DoCmd.Close acForm, frmName, acSaveNo
End Function
Sorry, i must of not be clear. And BTW, thank you for taking the time to discuss with me, that goes for all of the users that commented as well!!!When you delete a form, rest assured that no data is lost. All your information is safely retained in the tables of your database. The tables don't care if you make or remove forms that work with them, so there's no issue with the method. Just double check that the info you put in the form is saved in the table before you delete the form and you'll be fine.
You can disable the close button of the form and make a button that takes care of the closing, like:
Rich (BB code):Private Sub Comando0_Click() 'make form Dim newForm As Form Set newForm = Application.CreateForm 'define some utilitary variables Dim i As Long, j As Long, fieldCount As Long Dim someValues As String 'set an imaginary number of textboxes 'could be your field count fieldCount = 10 'define placeholder variable for combos Dim currCombo As ComboBox 'loop field count For i = 1 To fieldCount 'make combos Set currCombo = Application.CreateControl(newForm.Name, acComboBox) 'give them some props currCombo.RowSourceType = "Value List" currCombo.Top = i * 500 currCombo.Left = 600 currCombo.Width = 5000 currCombo.Height = 300 'add some data for the combo 'guess it'll be dynamic For j = 1 To 3 someValues = someValues & " something in combo " & i & " (" & j & ")" & "," Next j currCombo.RowSource = someValues 'restart strings for next combo someValues = "" Next i Dim closeButton As CommandButton Set closeButton = Application.CreateControl(newForm.Name, acCommandButton) closeButton.Caption = "Close form" closeButton.OnClick = "=CloseWithoutSave(""" & newForm.Name & """)" 'give it some name for show newForm.Caption = "MyForm" 'add code newForm.HasModule = True 'open form DoCmd.OpenForm newForm.Name 'you don't have to save it End Sub
And in a module:
Code:Public Function CloseWithoutSave(frmName As String) DoCmd.Close acForm, frmName, acSaveNo End Function
That way you discard the pop up asking you to save changes. The form needs to be discarded, if you save it, it will eventually become unusable.
I have not analyzed your actual needs, but I'm sure that you and everyone reading the thread will benefit from a sample of the data in its initial state and its target state, so we can all come up with a reasonable workflow for you.
Hi PatMicrosoft Access 2016 Maximum Limits and Specifications
Microsoft Access 2016: maximum limits and specifications ... Microsoft Access training in Toronto, Ontario, Canada. Our instructor-led courses are offered in downtown Toronto.www.avantixlearning.ca
View attachment 111210
The Excel files are given to me via USB stick to be imported into access. The Excel given to me are the main files used to update the tables and get a snapshot of the connected network. There is no middle-man here, simply an app in access that shows the data we need (intranet) to see from the connected network (Internet).If you want to update multiple different file types, why involve a middle-man? Just open the file and update it. Adding Access to the middle adds complexity but doesn't otherwise appear to add value.
I don't know what this means. If you are not connected to the network, how are you accessing the files?
I checked your files. I think I understand what you need. I don't have time left today, but I can give it a try tomorrow. Nothing will be stored in Access, right? you just want to manage your files. Is that correct?Attached is a sample of the Tbl_sow table in a pre and post status from an update. Note that the post result would be an excel pulled in and the update would update the table from that excel. All good when fields headers match. What i would like is to pull in any excel file, show the table and the file headers, and then allow the user to choose what field of the Excel is to be matched with the table field. Instead of hard coding things. I will lots of files coming in to update various tables and i do not want to have to alter the file to match headers.
Hi,I checked your files. I think I understand what you need. I don't have time left today, but I can give it a try tomorrow. Nothing will be stored in Access, right? you just want to manage your files. Is that correct?
In the example you provided, the two sheets have matching headers, can you describe 3 scenarios of what you need? Like... first I import a source workbook, the form parses its headers, then I import a target workbook and the form parses its headers too... then I choose what ranges from the source workbook go into the target workbook... etc... something like that?
Hi,That's a different take on the problem and would not require building forms and controls on the fly as you envisioned.
However, I question this as a design option. Importing data is not as simple as matching columns. Data imported this way should be validated as it is imported. Some columns will be required, there may be instances where you need to prevent a file from being imported multiple times, some columns might need specific types of validation. You can, without too much difficulty Pick a spreadsheet and then using a combo, pick a table. Then you have a subform bound to a cross reference table. The first column has a combo that lists column names from the spreadsheet. Then you have a combo that is dependent on the table combo in the parent form that lists the columns of the selected table. It is the subform that lets you match which columns from the spreadsheet go to which columns in the selected table. You can even run a query after the table is selected that populates the subform with all columns that match by name so the user only has to pick the odd columns.
But, what if you don't have a required field, what if the required field is empty in some rows? Where are you really going with this? You need to put this into context so we have a sense of how best to suggest making this mapping table. Once you have a mapping table, then it is pretty simple to build a query. You can even store the query and store its name in the header table of the cross reference. That way, the user only needs to do the mapping once.
Cool, so what is next?OK,
I think I got the PRESET (Excel matching table headers) working, attached are two picture, one when matching, or when not.
Well,Cool, so what is next?
' Create the mapping table
Set strCreateTable = CurrentDb.CreateTableDef(strMappingTable)
' Adding table fields to request
strCreateTable.Fields.Append strCreateTable.CreateField("AutoID", dbInteger)
strCreateTable.Fields.Append strCreateTable.CreateField("TargetTbl", dbText)
strCreateTable.Fields.Append strCreateTable.CreateField("SourceTbl", dbText)
' Process the request
CurrentDb.TableDefs.Append strCreateTable
Application.RefreshDatabaseWindow
There is no issue with binding an ADO recordset to a form and be updateable. Never heard any issues with reliability. "Just not safe"??On a similar topic warning things never to attempt in Access / VBA....
Several years ago I was involved in a discussion in this form about the possibility of getting an Access Form bound to an ADO.RecordSet rather than a DAO.RecordSet object. I still have the prototype form we arrived at.... as the best we could get it working.... so I was hoping the filename would assist in relocating the thread. Alas, no...
Oh!!! Here it is.... I changed search keywords, and located it....
"Fabricated ADO recordset - adding records"
Fabricated ADO recordset - adding records
Lagbolt has kindly provided an example of a fabricated ADO recordset bound to an ADO recordset here: http://www.access-programmers.co.uk/forums/showthread.php?t=258210 and it is reattached here. I have been unable to discover how to add records using the form. So, what needs to be changed, so...www.access-programmers.co.uk
My example code is attached to the thread.
I have never used Access Forms bound to an ADO.RecordSet out side this thread / prototype. It is just not safe / reliable.