Newb Question on linking tables

You wouldn't need the SeriesID, as the the comic is already linked to the series, and the attachment links to the comic.

Remember, you only want to store each piece of actual data once.
 
ya, I find myself trying to do duplicates at times... a hard habit to break.

2 questions on picture storage in general, on my series picture for instance there would only ever be 1 picture. Does that mean it safe to store that picture in tblseries?

Also having played with the paperclip on the form design, as well as in the tbl is there a way to set up so you can only store 1 picture? As well as potentially instead of using the paperclip in form which shows a paperclipthen () showing total number of pictures... that () I dont like so is it possible to use a button that simply says add image or something along those lines.

I know I could do a seperate form that pops up with a button that would then have the paperclip on it but Im just trying to streamline and look nice at the same time if at all possible.

Last question for now, say I wanted to set up a form so it was wider IF I had a picture and narrower if it wasnt... where would I put an if statement at for that? I know I can edit a picture width with Me.InsideWidth = 15000 something like that, I just dont know where to put it lol
 
May of got this one on my own... Im learning lol

I have:

Private Sub Form_Load()
If IsNull(Me.SeriesPicture) Then
Me.InsideWidth = 5700
Else
Me.InsideWidth = 10260
End If
End Sub
 
ya, I find myself trying to do duplicates at times... a hard habit to break.

2 questions on picture storage in general, on my series picture for instance there would only ever be 1 picture. Does that mean it safe to store that picture in tblseries?

If there's no chance of there ever being more than one picture, then yes, it's fine to add that as a field in the appropriate table. If the picture is assigned to the series, then tblSeries. If one can be assigned to a given comic, then it would be in tblComics. If both are possible, then obviously you'd want a field in each of those tables, although you should make the names different from each other just to save yourself some headaches down the road.

Also having played with the paperclip on the form design, as well as in the tbl is there a way to set up so you can only store 1 picture? As well as potentially instead of using the paperclip in form which shows a paperclipthen () showing total number of pictures... that () I dont like so is it possible to use a button that simply says add image or something along those lines.

I'm not entirely sure what you're asking here, but if if you've just included a picture field on either the series or the comic tables, then you'd only be able to add one picture; ie - the field would be either blank, indicating no picture, or else it would have a reference to the picture.

Now are you planning on storing the pictures in the database? If so, keep in mind images can get large, and Access is hardcapped at 2GB in size.

Oh, and it's totally possible to create a button that says 'add image' and then does whatever you need to do; it'll probably just take some work in VBA.

I know I could do a seperate form that pops up with a button that would then have the paperclip on it but Im just trying to streamline and look nice at the same time if at all possible.

Last question for now, say I wanted to set up a form so it was wider IF I had a picture and narrower if it wasnt... where would I put an if statement at for that? I know I can edit a picture width with Me.InsideWidth = 15000 something like that, I just dont know where to put it lol

Personally, I'd use Me.Width, not Me.InsideWidth. The former sets the width of the form, the latter sets the width of the window containing the form. Other than that very minor quibble, looks good. One thing, though - when posting code here, please make sure to use the code tags and that you've indented your code property. Makes it a LOT easier to read when it's more than just a few lines. Trust me, it makes figuring out what's really going on much much easier when something inevitably breaks.
 
So in an effort to find a better solution to having a picture but not having access store them I tried using a regular short text field and typing in the filename and directory into t hat txt filed, then using that as the control source for a regular image in the form design screen.

That would allow me to only have 1 file per comic or series also should keep the size of the database down.

So my next question... is there a way to use a choosefile popup window type thing when filling in that directory? that would be easier to choose what to populate that txtfield with.

I mean the popup window that alot of programs have similar... the same type of window that pops up in the attachment window when you click add
 
ok... check that question I think I figured it out mostly, I really am getting better then I realized lola lil googling to get me in the correct direction and Im learning how to edit code more and more...

The following code is working well, I click the add edit picture it brings up a file selection dialoge and I can add one that then puts what I add into tblseries under the field Seriespicture

Im still having issues selecting nothing though so I can remove the picture Not entirely sure why but when I figure it out Ill post the correct code... if anyone sees this before I figure it out please let me know what Im doing wrong

Code I have now:


Code:
Private Sub picture_Click()
     Dim objDialog As Object

 Set objDialog = Application.FileDialog(3)

 With objDialog
   .AllowMultiSelect = False
   .Show
   If .SelectedItems.Count = 0 Then
     Me.SeriesPicture = ""
   Else
     Me.SeriesPicture = .SelectedItems(1)
   End If
 End With
 Set objDialog = Nothing
End Sub
 
Ok I figured it out and if someone selected cancel then it would set it to null but there was no way to select nothing and click ok, thats fine though I just went ahead and added more more command button and set it to delete picture that works just as well... heres my code for my pictures, basically what I was working on for the last day or so

Code:
Private Sub Form_Load()
    If IsNull(Me.SeriesPicture) Then
        Me.InsideWidth = 5700
        Me.Picturescreen.Visible = False
    Else
        Me.InsideWidth = 10260
    End If
End Sub

Private Sub picture_Click()
     Dim objDialog As Object

 Set objDialog = Application.FileDialog(3)

 With objDialog
   .AllowMultiSelect = False
   .Show
   If .SelectedItems.Count = 0 Then
     MsgBox "No file selected."
   Else
     Me.SeriesPicture = .SelectedItems(1)
   End If
 End With
 Set objDialog = Nothing
End Sub

Private Sub refresh_Click()
    Me.Picturescreen.Visible = True
    If IsNull(Me.SeriesPicture) Then
        Me.InsideWidth = 5700
        Me.Picturescreen.Visible = False
    Else
        Me.InsideWidth = 10260
    End If
End Sub

Private Sub Removepic_Click()
    Me.SeriesPicture = ""
End Sub


I did try to change insidewidth to me.width but it wasnt editing my form size dynamically like I wanted ofr some reason, not entirely sure why so I stuck with insidewidth
 
Yeah, that should work. I have a slightly more robust routine I use for opening a file dialog and can provide it for you if you'd like, but you definitely have the right idea there. My main addition to what you have is the addition of a file type custom type, which you can then apply as a filter.

Changing the width of the form itself doesn't change the width of the window, now that I think about it. Insidewidth is perfectly fine.

Edit: Ah, hell. Here you go. Save it for future use, too. It comes in handy.

Code:
Option Compare Database
Option Explicit
Option Base 0

'*** THIS MODULE REQUIRES MICROSOFT OFFICE OBJECT LIBRARY REFERENCE TO BE ENABLED ***


'File type enumeration used in FileSelect
Public Enum FileType
    ftAccess = 1
    ftAll = 2
    ftExcel = 3
    ftPDF = 4
    ftText = 5
    ftWord = 6
    ftImage = 7
End Enum

Public Function ValidateFileType(ByVal Data As FileType) As Boolean
'**************************************************
'*  Created By:     Scott L Prince
'*  Created On:     10/2/13
'*  Modified:
'*  Purpose:        Validates a submitted 'FileType' (see Enum) to ensure a valid value was submitted.
'*  Parameters:     Submitted FileType value.
'*  Output:         Boolean
'*  Comments:
'**************************************************

Dim LoopCounter As Long

On Error GoTo ValidateFileType_Err

    'Defaults
    ValidateFileType = False
    
    'Make sure that the number submitted for ExpectedDataType.Value is actually valid.
    'ftAccess is the first value (1); ftWord is the last value (6).
    For LoopCounter = FileType.ftAccess To FileType.ftImage
        If LoopCounter = Data Then
            ValidateFileType = True
            Exit For
        End If
    Next

ValidateFileType_Exit:
    Exit Function

ValidateFileType_Err:
    MsgBox "An error has occurred in procedure 'ValidateFileType'!" & vbCrLf & vbCrLf & _
           "Error:" & vbTab & vbTab & Err.Number & vbCrLf & _
           "Description:" & vbTab & Err.Description, vbOKOnly + vbCritical
    Resume ValidateFileType_Exit

End Function

Public Function FileSelect(Optional ByVal DefaultLocation As String, _
                           Optional ByVal TypeOfFile As FileType = ftAll, _
                           Optional ByVal AddTypeAll As Boolean = True) As String
'**************************************************
'*  Created By:     Scott L Prince
'*  Created On:     10/2/13
'*  Modified:
'*  Purpose:        Opens file selection box, then returns path of selected file to calling procedure.
'*  Parameters:     Default folder path (OPTIONAL)
'*                  Type of file expected (OPTIONAL)
'*                  Whether or not to include all files to the list (useful in saving).
'*  Output:         Path to selected file
'*  Comments:
'**************************************************

Dim fd As FileDialog        'File Dialog box
Dim DefaultPath As String   'Actual default location to be used.
Dim WshShell as Object

On Error GoTo FileSelect_Err
    
    'Validate the submitted FileType.  If it fails, use ftAll.
    If Not ValidateFileType(TypeOfFile) Then TypeOfFile = ftAll
    
    'Determine if a default location was supplied.
    If IsMissing(DefaultLocation) Or Len(DefaultLocation) = 0 Then
        
        'No default was supplied, so use the user's 'My Documents' folder.
        Set WshShell = CreateObject("WScript.Shell")
        DefaultPath= WshShell.SpecialFolders("MyDocuments")

    Else
    
        'User passed a default location, so use it.
        DefaultPath = DefaultLocation
    End If

    'Set the options for the actual file dialog box.
    Set fd = Application.FileDialog(msoFileDialogFilePicker)

    With fd
        .AllowMultiselect = False           'Only one file will be opened.
        .InitialFileName = DefaultPath      'Fill in the initial folder path.
        .Title = "Select file to open."     'Dialog box title.
        .Filters.Clear                      'Clear existing filters, if any.
        
        'Add the appropriate filter for the file type selected.
        Select Case TypeOfFile
            Case ftExcel
                .Filters.Add "Excel File", "*.xls; *.xlsx", 1
            Case ftWord
                .Filters.Add "Word Document", "*.doc; *.docx", 1
            Case ftAccess
                .Filters.Add "Access Database", "*.mdb; *.mdr; *.mde; *.accdb; *.accde; *.accdr"
            Case ftText
                .Filters.Add "Text File", "*.txt", 1
            Case ftPDF
                .Filters.Add "PDF File", "*.pdf", 1
            Case ftImage
                .Filters.Add "Image file", "*.jpg; *.jpeg; *.png; *.gif; *.bmp"
            Case ftAll
                .Filters.Add "All Files", "*.*", 1
            Case Else
                .Filters.Add "All Files", "*.*", 1
        End Select
        
        'Add an "All Files" filter if it isn't already included and AddTypeAll is TRUE.
        If TypeOfFile <> ftAll And AddTypeAll = True Then .Filters.Add "All Files", "*.*", 2
        
        'Open the dialog box and return the user's response.
        If .Show = -1 Then
            'User selected a file.
            FileSelect = .SelectedItems.Item(1)
        Else
            'User did NOT select a file.
            FileSelect = "CANCEL"
        End If
    End With

FileSelect_Exit:
    On Error Resume Next
    If Not fd Is Nothing Then
        fd.Filters.Clear
        Set fd = Nothing
    End If
    If Not WshShell Is Nothing Then Set WshShell = Nothing
    Exit Function
    
FileSelect_Err:
    MsgBox "An error has occurred in procedure 'FileSelect'!" & vbCrLf & vbCrLf & _
           "Error:" & vbTab & vbTab & Err.Number & vbCrLf & _
           "Description:" & vbTab & Err.Description, vbOKOnly + vbCritical
    Resume FileSelect_Exit

End Function
 
Last edited:
tblstorageloc
-ID(needed field but not for my purposes so hidden)
-BoxID (linked to Box ID above)
-ComicID (linked to my tblcomics)

Every Table should have a Primary Key, and I find the best one to use is Autonumber.

Using anything else may result in using two or more fields together to come up with something unique.
 
Every Table should have a Primary Key, and I find the best one to use is Autonumber.

Using anything else may result in using two or more fields together to come up with something unique.

Yeah, I was fairly certain that the table he listed as ID was a PK, based on his description.
 
ya sorry ID is primary Key... I know its needed for access, I just wont be using that field so I have it as a hidden field..


Say in my series form, I wanted to have a box that listed how many comics I have in that series, what would be the best way to show in that form how many instances of that particular series ID were in the series field in my tblcomics? Would I use the count function somehow?
 
I just wont be using that field so I have it as a hidden field..

What does this mean. How do you hide a Field and why.
 
oh just in the table itself I hid that column so I wouldnt see it... its not something I use

Thanks for that code btw frog I'll change mine up with it, its handy :) ty
 
ok I figured out my previous question... basically what it does when Im looking at the various storage boxes available it allows me to see the total boxes of that type available as well as the capacity of whichever box I have selected at the time...

Heres the code

Code:
Private Sub list_Click()

Me.qty.Caption = DLookup("[Capacity]", "tblstorageboxtypes", "[Boxtype] = '" & Me.list & "'")

Me.totalbox.Caption = DCount("[Boxtype]", "tblstorageboxes", "[Boxtype] = '" & Me.list & "'")

End Sub

Sorry for pasting all this code when I figure it out myself... its just when I google things and I see people answer their own questions without ever saying how... well it bugs me :) so if I post a question I also post the answer if I figure it out.


a question however on not duplicating things between tables... in my tblstorageboxtypes I have Boxtype and capacity as my fields, in tblstorageboxes I hjave BoxID, Boxtype, Active, Boxnumber, and boxfull

Would I be better off instead of using boxtype which is a list that I have linked to box type in the first table... anyway would I be better off adding a boxid to the tblstorageboxtypes and using that number in tblstorageboxes instead of using the storagebox name

For instance I would ahve a record in tblstorageboxtypes that has Longbox it would be the only isntance of that name so its unique. which is why I figured I could use that identifier in my other table.

Is that ok or would I be better off with a actual ID number
 
As a general rule, you shouldn't use any actual data as a primary key. That's why all my suggestions used an ID field that was autonumbered.

As to having Boxtype, you would have BoxtypeID as a primary key in tblStorageBoxTypes, and as what's called a foreign key in tblStorageBoxes. You then link those together on the relationships screen in a one-to-many relationship with tblStorageBoxTypes on the one side.

This actualy saves space and makes the system easier to use. The space is saved because a number (the ID) is generally smaller than text. The ease of use is twofold - you not only no longer run the risk of mistyping the box type, but a table is easier to maintain and update than is a multivalue field. It also gets you out of having to maintain manual lists in combo boxes. (It's trivially easy to use a query based on the table as the row source in a combo box.)

Unless you have a pressing need, it's almost always good to keep the ID number.
 
That is a prevalent myth about Access. There certainly are cases when a key is not only unnecessary but detrimental to performance.

I have had this argument on this forum before.

http://www.access-programmers.co.uk/forums/showthread.php?t=201680&page=2

Galaxiom. You are correct in saying that some tables don't need a PK. However by stating this aren't you just helping someone who is already confused become even more confused. You are in fact making things more difficult for the OP and not helping at all.

You did not have an argument. It was merely a case of you making a statement which went unchallenged.

You also said "detrimental to performance." I cannot see how adding another field slows down or if you prefer is detrimental. Mind you this is coming from a person who believes that the joining of fields to form a unique reference is just as good if not better than a single Autonumber.
 
I guess I should change up how my tbl publisher interacts with tblseries then too

atm tbl publisher only has 2 fields: ID, and Publisher

Then via form when setting publisher in tblseries my form makes a list by listing off all the fields from t he publisher column in tblpublisher

So I should basically in tblseries store the ID number of the publisher instead I guess

I just assumed that this was adding extra work for access when I could just use that list in a form once and t hen access woudlnt have to cross reference again since the correct data would be stored in tblseries... I guess I figured having to look up a seperate record would take more time and processing power then just having to read off a field without having to open a second record then read off the data from there instead.
 
I'm not entirely certain what you're saying here. A two-field table is far from uncommon - it's easier to maintain lists for combo boxes that way than any other. You just have to make sure to create and maintain the table relationships in the relationships tab.

You can still have forms present data pulled from multiple sources - gathering data in that manner is one of the primary uses for queries/SQL statements.

Edit: Here, this is the basic layout I see for your database from what we've discussed. I tossed a couple other fields I thought of into the storage box type table, but that's about it.

Edit 2: I forgot to add in the attachment location field we talked about. That would be in tblComics.
 

Attachments

  • ComicRelationships.JPG
    ComicRelationships.JPG
    60.4 KB · Views: 95
Last edited:
Frothingslosh

Just a couple of suggestions on your design.

Why do you use the letters ID. Would not ConditionPK be just as good as ConditionID_PK but less letters and faster to type. You could apply the same rule for all of your Keys. This will make no difference to performance etc. I just think it is a little tidier.

tblPublishers is not following either rule. ID_PK or PK

tblStorageTypeID_PK Just does not look right. It appears to be lacking a description like BOX K9 104 which then has the other fields to describe it better like you have. Capacity might be that field which describes the box. eg a Box of 1x1x1 = a 1 Litre Box.

I realise that this is not your Database. You seem to have a good handle on it so I am just adding my thoughts for the OP and You to discuss.

Cheers.
 

Users who are viewing this thread

Back
Top Bottom