Posts

Showing posts with the label ms-access

INSERT SQL works only with hard coded values

Image
Clash Royale CLAN TAG #URR8PPP INSERT SQL works only with hard coded values Cannot insert a variable using INSERT in MS ACCESS. the insert works great when I insert a hard-coded value such as dbs.Execute "INSERT INTO Flights " _ & "(FlightID) VALUES " _ & "('2');" But fails with a variable Private Sub MainSaveBtn_Click() Dim dbs As Database Set dbs = CurrentDb Dim id As Integer id = 20 Debug.Print id dbs.Execute "INSERT INTO Flights " _ & "(FlightID) VALUES " _ & "('id');" dbs.Close End Sub *Flights table has only one Integer colum named FlightID What am i missing here? You are trying to insert the text 'id' into an integer column. – pritaeas 18 mins ago ...

Ms Access Table Design - list or new table

Image
Clash Royale CLAN TAG #URR8PPP Ms Access Table Design - list or new table I have a table: tblA ID = Autonumber Price = Number Name = Text The field [Name] contains values from a list. The list has 2-3 values. I will add 2more values in the list, so total 5values. What is better for performance for my database. The field to be list or create another table and place there the values? What is better for database size and speed? New Design: tblA tblB ID = Autonumber NameID = Autonumber Price = Number Name = Text NameID = Number Thank you. Go for tables as it easy to maintain & flexible. To speed up you can create an index on the field. – Santosh 57 secs ago By clicking "Post Your Ans...

Add a number to a field based of the number of occurences of specific text in another field

Image
Clash Royale CLAN TAG #URR8PPP Add a number to a field based of the number of occurences of specific text in another field I have a field that has several selections for trainings that can be input into my access database. I have an index set to not allow duplicates where the training title and date match, but there is one generic training that I'd like to allow to have duplicates. I'm thinking that if I can create another column with something like an auto number to the index then that might solve my problem. However I don't know how to do that. What I'm thinking is that each time the training "Additional Training" is selected, this other column will detect that and add an auto number (or other unique identifier). It will not do this for any other entries, thereby allowing only that one training to be duplicated. Any suggestions? By clicking "Post Your Answer", you acknowledge that...

If Query Already Exists Then Delete the Entire Query

Image
Clash Royale CLAN TAG #URR8PPP If Query Already Exists Then Delete the Entire Query I have a form that creates two queries, exports them to Excel and then deletes them. However, when I hit an error on my exporting, it doesn't make it the deletions. How would I go about checking to see if they already exist? And if they do, delete them so I can re-create them with the new/updated data? Code so far: Dim qdfNewQry As Object Dim qdfNewWS As Object '//----- qdfNewQry If Not IsNull(DLookup("myExportQry", "MSysObjects", "Name='myExportQry'")) Then CurrentDb.QueryDefs.Delete qdfNewQry.Name Set qdfNewQry = CurrentDb.CreateQueryDef("myExportQry", exportQry) Else Set qdfNewQry = CurrentDb.CreateQueryDef("myExportQry", exportQry) End If '//----- qdfNewWS If Not IsNull(DLookup("myExportWS", "MSysObjects", "Name='myExportWS'")) Then CurrentDb.QueryDefs.Delete qdfNewWS.Name ...

Group by random column in ms access

Image
Clash Royale CLAN TAG #URR8PPP Group by random column in ms access I need something like this in MS ACCESS SQL SELECT ID, col1, col2, random(col3) FROM table GROUP BY ID, col1, col2 NOTE: I want to remove duplicates choosing random value of col3. INPUT: +----+------+------+------+ | Id | col1 | col2 | col3 | +----+------+------+------+ | 1 | A | B | 7 | +----+------+------+------+ | 1 | A | B | 10 | +----+------+------+------+ RESULT: +----+------+------+------+ | Id | col1 | col2 | col3 | +----+------+------+------+ | 1 | A | B | 7 | +----+------+------+------+ REQUERY: +----+------+------+------+ | Id | col1 | col2 | col3 | +----+------+------+------+ | 1 | A | B | 10 | +----+------+------+------+ A random column from the table or a predefined column that grabs a random value? – Edward 18 hours ago ...