moke123
AWF VIP
- Local time
- Today, 13:56
- Joined
- Jan 11, 2013
- Messages
- 4,414
And you wonder why your struggling?My db is not relational. Everything is in one table so I've no need for P or F keys, and their complications.
And you wonder why your struggling?My db is not relational. Everything is in one table so I've no need for P or F keys, and their complications.
Not trying to be a jerk, but trying to give some tough-love. it seems you are trying to outsmart everyone who has ever built a proper Access application. By making it less "complicated" you have come up with some very complicated way of doing things. I have made thousands and helped people with thousands of Access databases, but I cannot make heads or tails of what you are trying to do. I think what you want to do is a trivial application, and you are wasting a ton of time trying to come up with completely new ways to do things.My db is not relational. Everything is in one table so I've no need for P or F keys, and their complications. One table is so easy to update and maintain. You asked How are you relating tracks to albums. There's no relationship, the tarcks *are* the album.
So yes, this may be different to what is conventional, but will be better for us than any "nicely Formatted" music database as it's features are purpose built.
I wrote this as a generic function so that anyone can build a wrap-able listbox. It actually works better than I thought, so maybe the Idea is not so far fetched. However to make it make any sense, you need to know that the subsequent lines belong to the same record. All records in a database have a PK. Sorry that is not disputable. In most comboboxes you display a readable text but bind it to a hidden column that holds the PK.You set list colums to 2, the first may have a width of 0. Not sure why that might be yet. A part of the code exits if lst, arr(I))
The code was written to break on full words or break within a word. The latter was assuming you might have one continuous long string. In your case you will never likely have a single word bigger than the visible display. The code could be modified easily to break on whole words where you can and if a single word is bigger than the visible display then break within that word. I cannot think of any reasonable data that would have those properties. Maybe something likeA part of the code exits if lst, arr(I)) > visWidth. I doubt this would ever happen but could a space be inserted/used so it can't happen ?
Based on experience I have seen a lot of people get enamored with building fancy forms and focus on that and not worry about the underlying data structure. To me that is like worrying about getting the cabinets and tile in before getting the house properly framed. If your house is not framed square, plum and level everything after that gets real hard to do. Spending the time to get proper normalized tables will save a ton of time in the long run and make everything much easier. If not the workarounds begin to snowball and everything gets every more complicated to do simple tasks. I have seen two tables, which seem like they should be somehow related. One looks like a list of albums (tblMain) and the other kind of looks like the beginning of a tracks table, although the data in it makes no sense.Maybe I place too much emphasis on getting the desired result anyhow but I am enjoying developing this and there is a 'master plan'.
The thing that makes Excel so difficult to use as a "database" is that the presentation layer and data layer are merged. So the users see the same names you code with. That isn't the way that a relational database works. You use meaningful names when you are coding to avoid confusion and to minimize the learning curve for your successor and you use whatever the users wants as label names. Not sure why the users would want obscure abbreviations for labels either when they are no longer necessary. Keep in mind that the vast majority of all application development is done by people who are NOT domain experts. You are a domain expert but you are in over your head with Access. Access is like any other tool. If you use it the way it was intended to be used, it will serve you well. If you use it incorrectly, it will cut off your toes.I know the field names aren't what you'd normally use in Access, but I wanted to keep them for compatibilty
That is the heart of your problem. You will fight with Access over everything and Access will win. When you start using Access as a RAD tool rather than a spreadsheet, you will have a much easier time. Many of the display formats you like can be replicated using crosstabs but that is not how you would store your data. You can even export the data back to Excel to make reports if that works better.So it's not really an Access database, it just uses Access as means to an end.
Each and every time...You will fight with Access over everything and Access will win.
Private Function GetTextLength(pCtrl As Control, ByVal str As String, _
Optional ByVal Height As Boolean = False)
Dim lx As Long, ly As Long
' Initialize WizHook
WizHook.Key = 51488399
' Populate the variables lx and ly with the width and height of the
' string in twips, according to the font settings of the control
WizHook.TwipsFromFont pCtrl.fontName, pCtrl.fontSize, pCtrl.FontWeight, _
pCtrl.FontItalic, pCtrl.FontUnderline, 0, _
str, 0, lx, ly
If Not Height Then
GetTextLength = Abs(lx)
Else
GetTextLength = Abs(ly)
End If
End Function
Public Sub ClearTempTable()
CurrentDb.Execute "delete * from tblTempList"
End Sub
Public Function LoadWrapListTable(lst As Access.ListBox, longString As Variant, Optional PK As Variant = "0", Optional wholeWords = True) As String
Dim visWidth As Long
Dim visWidthInches As Long
Dim arr() As String
Dim I As Integer
Dim txt As String
Dim txtLength As Long
Const buffer = 400
'I think this makes sense only with one visible column little more complicated if not
lst.RowSourceType = "Table/Query"
lst.RowSource = "SELECT tblTempList.ID, tblTempList.Display FROM tblTempList ORDER BY tblTempList.Sort"
visWidth = lst.Width - buffer
lst.ColumnCount = 2
lst.ColumnWidths = "0;" & visWidth / 1440 & " in"
If Not IsNull(longString) Then
arr = Split(longString, " ")
For I = 0 To UBound(arr)
If txt = "" Then
txt = txt & Trim(arr(I))
Else
txt = txt & " " & Trim(arr(I))
End If
txtLength = GetTextLength(lst, txt)
If GetTextLength(lst, arr(I)) > visWidth Then
MsgBox "Whole words are greater than visible length. Exiting", vbInformation
Exit Function
End If
If txtLength >= visWidth Or arr(I) = vbCrLf Then
If txtLength > visWidth Or arr(I) = vbCrLf Then
' roll back
txt = Left(txt, Len(txt) - Len(arr(I)))
If I > 0 Then I = I - 1
End If
' Debug.Print PK & "; " & txt
txt = Replace(txt, "'", "''")
CurrentDb.Execute "Insert into tblTempList (ID,Display) values ('" & CStr(PK) & "', '" & txt & "')"
txt = " "
End If
Next I
If txt <> "" Then
' Debug.Print PK & "; " & txt
txt = Replace(txt, "'", "''")
CurrentDb.Execute "Insert into tblTempList (ID,Display) values ('" & CStr(PK) & "', '" & txt & "')"
End If
End If
End Function